2013-07-18 72 views
-4

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

回答

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) 
+0

谢谢你的好工作。如果你把结果放在10个向量中,或者以200乘10的矩阵表示。我对它感兴趣。再次感谢。 – Faizi

+0

我编辑了请求的更改,让我知道它看起来如何 –

+0

非常感谢。它很棒,我也想要。谢谢@哈里森 – Faizi