Question:
So I am trying to create a list of all combinations of 14 numbers that have been split into two separate groups. For example, the beginning of this list may look like:Group X | Group Y |
---|---|
1 | 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
1, 2 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
1, 2, 3 | 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
And so forth. This list would consist of 16384 possible combinations of these 14 numbers when split into two groups. (2^14) Any ideas on how to do this in R?
Answer:
You may try (for2^3
cases)x <- expand.grid(replicate(3, c(T,F), simplify = F)) apply(x, 1, function(x){list(group1 = c(1:3)[x], group2 = c(1:3)[!x])}) [[1]] [[1]]$group1 [1] 1 2 3 [[1]]$group2 numeric(0) [[2]] [[2]]$group1 [1] 2 3 [[2]]$group2 [1] 1 [[3]] [[3]]$group1 [1] 1 3 [[3]]$group2 [1] 2 [[4]] [[4]]$group1 [1] 3 [[4]]$group2 [1] 1 2 [[5]] [[5]]$group1 [1] 1 2 [[5]]$group2 [1] 3 [[6]] [[6]]$group1 [1] 2 [[6]]$group2 [1] 1 3 [[7]] [[7]]$group1 [1] 1 [[7]]$group2 [1] 2 3 [[8]] [[8]]$group1 numeric(0) [[8]]$group2 [1] 1 2 3 [/code]
If you have better answer, please add a comment about this, thank you!