想请教,当查看sample函数的例子时,发现有一个bug,即生成的一个长度为10的样本,这是为什么呀?谢谢~
# sample()'s surprise:
x <- 1:10
sample(x[x > 8]) # length 2
sample(x[x > 9]) # oops -- length 10!
sample(x[x > 10]) # length 0
## safer version:
resample <- function(x, ...) x[sample.int(length(x), ...)]
resample(x[x > 8]) # length 2
resample(x[x > 9]) # length 1
resample(x[x > 10]) # length 0