The second one (x2) uses the same mean/sd for the 20000 variates. If you want to change the mean/sd for each variate:
> x3 <- round(replicate(20000, rnorm(1, runif(1, 4, 6), runif(1, 2, 3))), 6) > head(x3) [1] 5.648530 5.689563 2.945512 3.915723 8.527447 0.298535 ------- David C -----Original Message----- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David L Carlson Sent: Tuesday, August 2, 2016 2:40 PM To: Adrian Johnson; r-help Subject: Re: [R] generate a vector of random numbers within confines of certain parameters Try > set.seed(42) > x1 <- round(rnorm(20000, 4, 2), 6) > head(x1) [1] 6.741917 2.870604 4.726257 5.265725 4.808537 3.787751 Setting the seed makes the sequence reproducible, but if that is not important, you can leave it out. This assumes you want a normal distribution and you want to specify the mean and standard deviation. If you want those to be selected randomly. The following does that using uniform distributions so each mean and standard deviation is equally likely within the range: > x2 <- round(rnorm(20000, runif(1, 4, 6), runif(1, 2, 3)), 6) > head(x2) [1] 4.054289 4.745569 5.795536 6.316750 4.370713 5.586646 ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Adrian Johnson Sent: Tuesday, August 2, 2016 1:57 PM To: r-help Subject: [R] generate a vector of random numbers within confines of certain parameters Dear group, I am trying to generate a vector of random numbers for 20K observation. however, I want to generate numbers (with 6 decimal places) within the range of Std. Dev : 2-3 mean : 4-6 Is there a method to generate numbers with 6 decimal places under these parameters thank you. Adrian ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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.