I get some unexpected behavior when sampling from a sequence stepwise vs replicating the exact same sampling. If I repeatedly execute
sample(seq(from = 0.9, to = 1.1, by = 0.01), size=1, replace=T)[1]
R will never sample anything > 1 and < 1.1, e.g. 1.07, 1.04, etc. while sampling anything else, e.g. 0.9, 0.97, 0.95, 1, 1.1, etc. However, replicating the same sampling e.g. 10 times will result in any value between and including 0.9 and 1.1.
replicate(10,sample(seq(from = 0.9, to = 1.1, by = 0.01), size=1, replace=T))
Why is that?
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)