Rahul Agarwal
Rahul Agarwal

Reputation: 4100

Transforming list into smaller subset in R without repetition

I have searched enough but couldn't find the answer. If this is already asked please post the link.

I have a list which looks like this

sample.list <- as.list(c("a","b","c"))

I want to transform this list like below:

  1. {a,b}
  2. {a,c}
  3. {b,c}

I don't want entries like {b,a} or {c,b} etc. This is just sample list, actual list can be of any length

Upvotes: 1

Views: 43

Answers (1)

akrun
akrun

Reputation: 887158

We can use combn

 combn(sample.list,2)

Upvotes: 3

Related Questions