Hello, I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
Eric ESPOSITO <eric.esposito at gazdefrance.com> wrote:> I would like to sample a population but the result needs to be > reproducible, using 'runif' or 'sample' is the good way to do it but I > can't manage to make the results reproducible even with the 'set.seed' > function. > My aim is that th call to 'sample(1:100,10)' gives always the same result, > how can I do that?Can you give an example of set.seed not giving reproducible samples? set.seed(101) sample(1:100,10) [1] 38 5 70 64 24 29 55 32 58 50 set.seed(101) sample(1:100,10) [1] 38 5 70 64 24 29 55 32 58 50 -- Philippe Glaziou Epidemiologist
Hello, I already sent such an email before Christmas, but nobody answered, so here is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
With this sort of problem you will get better chance of a response if you reduce your program down to a small reproducable example which illustrates the behavior. Also give your R version and your OS version. When I try running sample(100,10) repeatedly on R 1.8.1 under Windows 2000 Pro it works fine:> f <- function() { set.seed(1); sample(100,10) } > > a <- f() > for(i in 1:1000) if (!identical(f(),a)) cat("not identical\n") >Note that no output was produced showing the random numbers were always the same. --- Date: Mon, 5 Jan 2004 13:07:08 +0100 From: Eric ESPOSITO <eric.esposito at gazdefrance.com> To: <r-help at stat.math.ethz.ch> Subject: [R] runif and sample with reproducibility Hello, I already sent such an email before Christmas, but nobody answered, so here is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html