I'm trying to write a program in R that when, given a vector, will return all possible tuples of elements from that vector.
For example: tuples(c('a','b','c')) = c('a','b','c'); c('a','b'); c('a','c'), c('b','c'); c('a'); c('b'); c('c')
I think it should return a list of vectors.
For reference, here is a program that does a similar function in Stata.
You can use combn
:
x <- 1:3
unlist(lapply(x, function(n) combn(x, n, simplify=FALSE)), recursive=FALSE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With