采样矩阵WR

时间:2013-07-18 11:05:58

标签: r

从大小为200的原始数据集中进行替换采样。计算每个值的频率,并将零值分配给非发生的值。迭代过程说10次并将结果存储在Matrix中。

1 个答案:

答案 0 :(得分:0)

你没有给出太多背景,所以这是我的解释:

## You didn't specify what we were sampling from, so I just took it as all numbers from 1 to 200
x <- 1:200

## Sampled from x in sizes of 50 (because you didn't specify how big), with replacement, 10 times    
samp <- list()

for (i in 1:10){
  samp[[i]] <- sample(x, size = 50, replace = TRUE)
}

results <- list()
results.mat <- 1:200
for (i in 1:10){
  results[[i]] <- table(factor(samp[[i]], levels = 1:200))  
  results.mat <- cbind(results.mat, results[[i]])
}

View(results.mat)