Imagine that we have three vectors:
v_1 = c("a", "b", "c", "d")
v_2 = c("e", "f", "g")
v_3 = c("h", "i")
I'd like to use R to retrieve a complete list of all combinations of these three vectors for all possible lengths under the condition that:
- we can pick a maximum of 1 element per vector (e.g., the combination "ab" shall be disregarded since they both belong to
v_1
) - order is not important (e.g., the combination "ae" and "ea" shall only be counted once).
Given that I have done the math correctly, we should end up with 59 distinct combinations of lengths 1 to 3. I've looked into the combn()
function, but it seems difficult (or impossible?) to apply the the two conditions. Does anyone a have suggestion for how to solve this in R?
Thanks!