Different results from sample() even setting a seed

90 Views Asked by At

I have a vector containing 1200 numbers (from 1 to 1200) and need to sample a set of them. I set a seed number expecting to be able to replicate the results but everytime I sort the same number from the same vector, I get different results. Am I missing something in the implementation of either the set.seed or in the sample() functions? I have also tried the caTools::sample.split() function and the issue persists.

set.seed(1)

ln <- 1:1200

test <- sort( sample(x=ln, size=5, replace = FALSE) )
test
[1]  242  319  447  687 1088

test <- sort( sample(x=ln, size=5, replace = FALSE) )
test
[1]   74  754  792 1079 1133

test <- sort( sample(x=ln, size=5, replace = FALSE) )
test
[1] 212 248 460 824 921
0

There are 0 best solutions below