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]]
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 <saggak1908 at 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 at 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. > >
So you need to cbind the four vectors together... ?cbind "saggak" <saggak1908 at 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 at 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.--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity.
Dear Mr Bedward and Mr Newmiller, Thanks a lot for the guidance. Really appreciated. Sagga K --- On Tue, 11/1/11, Michael Bedward <michael.bedward@gmail.com> wrote: From: Michael Bedward <michael.bedward@gmail.com> Subject: Re: [R] Generation of Normal Random Numbers To: "saggak" <saggak1908@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 <saggak1908@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 andD.> > 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, reproduciblecode.> >______________________________________________ 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]]