[R] set.seed and for loop

R Help rhelp.stats at gmail.com
Thu Jun 9 17:23:56 CEST 2011


There are certainly people that would know how the random functions
work better than I, but I believe you would need to simulate 22
datasets and then get the 23rd dataset.  So to restore the 23rd:

set.seed(1001)
for(i in 1:22){
  garbage = runif(50)
}
data[[23]] = runif(50)

Hope that helps,
Sam

On Thu, Jun 9, 2011 at 12:14 PM, Soyeon Kim <yunni0731 at gmail.com> wrote:
> Dear All,
>
> This is hard to describe so I made a simple example.
> set.seed(1001)
> total <- 0
> data <- vector("list", 30)
> for(i in 1:30) {
>  data[[i]] <- runif(50)
> }
> Let's call a data set runif(50).
> While the for loop is running, 100 data sets  are generated.
> I want to restore 23th data set (the data set generated in 23th for
> loop) without the loop.
> I've tried set.seed(1023) runif(50)
> but this is different data from the data set gotten from 23th for loop.
> How can I get 23th data set without the loop?
>
> Thank you,
> Soyeon
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list