Question

I am using sample() function for generating radnom data in R.

 x<-1:12
 sample(x)
 [1] 10  9  4  3 12 11  8  6  1  2  5  7

 x<-1:12
 sample(x)
 [1]  2  6  8 12 10 11  1  3  5  7  9  4

I get different set in two different call. Is there any way to generate the same set of records?

Regards

Was it helpful?

Solution

use set.seed(1) (or any number) for that

> set.seed(1)
> sample(x)
 [1]  4  5  6  9  2  7 10 12  3  1 11  8
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top