在sample()函数后存储剩余数字

时间:2015-04-22 00:09:26

标签: r random vector sample

score = c(22,20,30,12,29,21,18,31,27,29,22,48,13,18,10,11,17,10,22,28,14,19,30,22,9)

x <- sample(score,size=13,replace=FALSE) 
y <- # I want y to store the numbers that were left behind after sample()

如果我使用setdiff()函数,它将从分数列表中删除所有重复的数字,这不是我正在寻找的。

有人可以给我一些提示吗?

1 个答案:

答案 0 :(得分:4)

然后不要对值进行采样,对索引进行采样

score = c(22,20,30,12,29,21,18,31,27,29,22,48,13,18,10,11,17,10,22,28,14,19,30,22,9)

idx <- sample.int(length(score),size=13,replace=FALSE) 
x <- score[idx]
y <- score[-idx]