sample函数注意事项
生活随笔
收集整理的這篇文章主要介紹了
sample函数注意事项
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
# sample()'s surprise -- example
x <- 1:10sample(x[x > 8]) # length 2sample(x[x > 9]) # oops -- length 10!#意思就是,當選擇的子變量是一個大于零的整數(shù)時,比如sample(10),就會返回1:10中的隨機排列了,等同于sample(1:10,10,replace=FALSE)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
總結(jié)
以上是生活随笔為你收集整理的sample函数注意事项的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 金山词霸2009牛津with SP3完全
- 下一篇: Firefox七种武器之firebug