In R version 5.4.1, when I set the size parameter of sample() in the form 1000*(1-i), I sometimes get a output that is 1 value too short; this only seems to happen at values of i above 0.7, but the exact value where the error starts to occur varies.
set.seed(8375642)
x = seq(from = 0.1, to = 0.9, by = 0.1)
y = 1:1000
for(i in x){
print(paste(length(sample(y, 1000*(1-i), replace = T)), 1000*(1-i)))
}
[1] "900 900"
[1] "800 800"
[1] "700 700"
[1] "600 600"
[1] "500 500"
[1] "400 400"
[1] "299 300"
[1] "199 200"
[1] "99 100"
This does not happen without the (1-i) part:
set.seed(8375642)
x = seq(from = 0.1, to = 0.9, by = 0.1)
y = 1:1000
for(i in x){
print(paste(length(sample(y, 1000*i, replace = T)), 1000*i))
}
[1] "100 100"
[1] "200 200"
[1] "300 300"
[1] "400 400"
[1] "500 500"
[1] "600 600"
[1] "700 700"
[1] "800 800"
[1] "900 900"