Deb Deb - 9 months ago 37
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


We can use combn to get the unique combinations

t(combn(z, 3))

If we need to sample it

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