[R] set.seed and for loop

Duncan Murdoch murdoch.duncan at gmail.com
Thu Jun 9 17:21:00 CEST 2011


On 09/06/2011 11:14 AM, Soyeon Kim 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?

You can't.

To get the 23rd value again, set the seed to 1001, run the loop 22 
times, then the next one will be the 23rd.

Duncan Murdoch



More information about the R-help mailing list