Variant 1
I have a vector with n elements - let's say three for the sake of this example: elements <- c("A", "B", "C"). I would like to create a new vector containing all combinations of these n elements - regardless permutations but with the possibility to take 1 to n of them, such that I obtain:
combinations <- c("A", "B", "C", "AB", "AC", "BC", "ABC"). Would there be an automatic way to do this (and with any number of elements of course)?
Variant 2
I would like to do the same operation, but with elements also having the possibility to be negated. Such that I obtain: combinations <- c("A", "B", "C", "~A", "~B", "~C", "AB", "AC", "BC", "~AB", "A~B", "~AC", "A~C", "~BC", "B~C", "~A~B", "~A~C", "~B~C", "ABC", "~ABC", "A~BC", "AB~C", "~A~BC", "~AB~C", "A~B~C", "~A~B~C"). Again, I would like this to be automatic (and with any number of elements).
Could someone help me?