rw2*_*rw2 2 r permutation random-sample
我有一个很长的列表,其中包含相当多的重复项,例如100,000个值,其中20%是重复的.我想从这个列表中随机抽样,将所有值分组,比如400个.但是,我不希望任何后续组在其中包含重复值 - 即我希望每个组的所有250个成员都是唯一的.
我尝试过使用素食主义者,picante,EcoSimR的各种排列方法,但是他们没有做我想做的事情,或者似乎对大量数据感到困惑.
我想知道是否有一些方法使用我无法弄清楚的样本函数?任何帮助或替代建议将不胜感激......
正如nico所说,您可能只需要使用该unique功能.下面是一个非常简单的抽样程序,确保不会在各组之间出现重复(这不是完全合理的,因为您可以创建一个大样本......)
# Getting some random values to use here
set.seed(seed = 14412)
thevalues <- sample(x = 1:100,size = 1000,replace = TRUE)
# Obtaining the unique vector of those values
thevalues.unique <- unique(thevalues)
# Create a sample without replacement (i.e. take the ball out and don't put it back in)
sample1 <- sample(x = thevalues.unique,size = 10,replace = FALSE)
# Remove the sampled items from the vector of values
thevalues.unique <- thevalues.unique[!(thevalues.unique %in% sample1)]
# Another sample, and another removal
sample2 <- sample(x = thevalues.unique,size = 10,replace = FALSE)
thevalues.unique <- thevalues.unique[!(thevalues.unique %in% sample2)]
Run Code Online (Sandbox Code Playgroud)
要做eipi10提到的并获得加权分布,你只需要先得到分布的频率.这样做的一种方式:
set.seed(seed = 14412)
thevalues <- sample(x = 1:100,size = 1000,replace = TRUE,prob = c(rep(0.01,100)))
thevalues.unique <- unique(thevalues)
thevalues.unique <- thevalues.unique[order(thevalues.unique)]
thevalues.probs <- table(thevalues)/length(thevalues)
sample1 <- sample(x = thevalues.unique,
size = 10,
replace = FALSE,
prob = thevalues.probs)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7747 次 |
| 最近记录: |