Deb Deb - 1 year ago 79
R Question

All unique samples from a data set in R

Here's my data

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

if i do


This will give me 1 unique random sample of 3 from my data set.

I want to find all possible unique samples of 3 from my data set. In this case there will be 10 outcomes.

But how do I write a R code for it?

Please help

Answer Source

We can use combn to get the unique combinations

t(combn(z, 3))

If we need to sample it

t(combn(sample(z), 3))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download