Reputation: 3521
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
Upvotes: 1
Views: 1267
Reputation: 15458
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
Upvotes: 4