简体   繁体   English

来自 R 中数据集的所有独特样本

[英]All unique samples from a data set in R

Here's my data这是我的数据

z<- c("COP","CHK","BP","BHI","CVX")

if i do如果我做

 sample(z,3,replace=FALSE)

This will give me 1 unique random sample of 3 from my data set.这将从我的数据集中为我提供 1 个独特的随机样本 3。

I want to find all possible unique samples of 3 from my data set.我想从我的数据集中找到所有可能的 3 个唯一样本。 In this case there will be 10 outcomes.在这种情况下,将有 10 个结果。

But how do I write a R code for it?但是我如何为它编写 R 代码呢?

Please help请帮忙

We can use combn to get the unique combinations我们可以使用combn来获得独特的组合

t(combn(z, 3))

If we need to sample it如果我们需要sample

t(combn(sample(z), 3))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM