Select all possible tuples from a vector in R

I am trying to write a program in R which, when a vector is given, will return all possible tuples elements from that vector.

For example: tuples (c ('a', 'b', 'c')) = c ('a', 'b', 'c'); Taxi'); c ('a', 'c'), c ('b', 'c'); c ('a'); s ('b'); s ('s')

I think it should return a list of vectors.

For reference, here is a program that performs a similar function in Stata .

+3
source share
1 answer

You can use combn:

x <- 1:3
unlist(lapply(x, function(n) combn(x, n, simplify=FALSE)), recursive=FALSE)
+6
source

All Articles