I realized after posting that you can also just do this...

x <- matrix(rnorm(25 * length(m), m, s), ncol=4, byrow=TRUE)

Michael


On 11 January 2011 19:13, Amelia Vettori <amelia_vett...@yahoo.co.nz> wrote:

> Dear Mr Bedward and Mr Newmiller,
>
> Thanks a lot for the guidance. Really appreciated.
>
> Sagga K
>
> --- On *Tue, 11/1/11, Michael Bedward <michael.bedw...@gmail.com>* wrote:
>
>
> From: Michael Bedward <michael.bedw...@gmail.com>
> Subject: Re: [R] Generation of Normal Random Numbers
> To: "saggak" <saggak1...@yahoo.co.in>
> Cc: r-help@r-project.org
> Received: Tuesday, 11 January, 2011, 7:24 AM
>
> m <- c(1004.1, 1028.3, 1044.3, 861.4)
> s <- c(194.5899, 158.7052, 123.3000, 285.8695)
> x <- mapply(function(mi, si) rnorm(25, mi, si), m, s)
>
> Hope this helps,
>
> Michael
>
>
> On 11 January 2011 17:44, saggak <saggak1...@yahoo.co.in> wrote:
> > Dear R helpers
> >
> > I have a data frame as given below
> >
> > df = data.frame(A = c(776,827,836,995,855,1026,1203,1363,965,1195),
> >                        B =
> c(806,953,1049,1056,1243,764,1148,1162,948,1154),
> >                        C =
> c(959,1155,1193,1163,863,1070,1087,877,1132,944),
> >                        D = c(906,760,978,1170,1009,883,1007,960,828,113))
> >
> > # Actually the real data has number of vectors and not only A, B, C and
> D.
> >
> > m = as.numeric(lapply(df, mean))
> > s = as.numeric(lapply(df, sd))
> >
> > gives
> >
> >> m
> > [1] 1004.1 1028.3 1044.3  861.4
> >> s
> > [1] 194.5899 158.7052 123.3000 285.8695
> >
> > I need to generate 25 (normal) random numbers for each of these mean and
> corresponding standard deviation combination (m[i], s[i]). i.e. I need to
> have a table (dim 25 X  4) giving me random numbers.
> >
> >
> > rnorm(25, m[1], s[1])   rnorm(25, m[2], s[2])   rnorm(25, m[3], s[3])
> rnorm(25, m[4], s[4])
> >    ....................           .........................
> ...............                 .................
> >    ....................           .........................
> ...............                 .................
> >    ....................           .........................
> ...............                 .................
> >    ....................           .........................
> ...............                 .................
> >
> >
> >    ....................           .........................
> ...............                 .................
> >
> >
> > Kindly guide
> >
> >
> > Thanking in advance
> >
> > Sagga K
> >
> >
> >
> >
> >
> >
> >
> >        [[alternative HTML version deleted]]
> >
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to