Hi all, Is it possible to generate the same sample number of times in R? In SAS, using the option "seed" it is possible to reproduce exactly the same sample. Is there any such feature in R which I can use? For further clarity, for (i in 1:2) { samp = sample(1:1000,100,replace = FALSE) print(samp) } For the above simulation, is it possible to generate the same sampled units twice? Any suggestion would be gratefully acknowledged. Thanks, Santanu Santanu Pramanik JPSM,1218J Lefrak Hall University of Maryland,College Park Phone no.-301-314-9916 [[alternative HTML version deleted]]
On 02-May-07 23:25:18, Santanu Pramanik wrote:> Hi all, > > Is it possible to generate the same sample number of times in R? > In SAS, using the option "seed" it is possible to reproduce exactly > the same sample. Is there any such feature in R which I can use? > > For further clarity, > > for (i in 1:2) > { > samp = sample(1:1000,100,replace = FALSE) > print(samp) > }> > For the above simulation, is it possible to generate the same sampled > units twice? > > Any suggestion would be gratefully acknowledged. > Thanks, > SantanuHave a look at set.seed(): ?set.seed You will of course have to invoke it before you do your first run. You cannot find out what the seed was afterwards! For example (your example somewhat reduced): for (i in 1:2) { samp = sample(1:1000,10,replace = FALSE) print(samp) } # [1] 984 587 26 920 304 247 434 392 650 279 # [1] 178 619 458 208 389 629 988 263 598 308 for (i in 1:2) { set.seed(512534) samp = sample(1:1000,10,replace = FALSE) print(samp) } # [1] 271 106 570 621 257 663 399 454 983 805 # [1] 271 106 570 621 257 663 399 454 983 805 Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 03-May-07 Time: 00:56:43 ------------------------------ XFMail ------------------------------
?set.seed On Wed, 02 May 2007 18:25:18 -0500, Santanu Pramanik <spramanik at survey.umd.edu> wrote:> Hi all, > Is it possible to generate the same sample number of times in R? In > SAS, using the option "seed" it is possible to reproduce exactly the > same sample. Is there any such feature in R which I can use? > For further clarity, > for (i in 1:2) > { > samp = sample(1:1000,100,replace = FALSE) > print(samp) > } > For the above simulation, is it possible to generate the same sampled > units twice? > Any suggestion would be gratefully acknowledged. > Thanks, > Santanu > Santanu Pramanik > JPSM,1218J Lefrak Hall > University of Maryland,College Park > Phone no.-301-314-9916 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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.-- Kenneth Roy Cabrera Torres Cel 315 504 9339