I have a sequence that varies in length, for example. sort of:
items <- 1:4
I want to break it down into all sorts of combinations of the nnumber of sets. So to speak n- two, I want to return:
Set A Set B
----- -----
1 2 3 4
1 2 3 4
1 2 3 4
1 3 2 4
etc .. Location within sets does not matter, i.e. the set { 1, 2, 3} is { 2, 1, 3}. Sets cannot be empty.
Best I could come up with (using permnfrom the package combinat):
n <- 2
r <- 1:length(items)
arrangements <- NULL
for (i in 1:(n-1)) {
A <- r[(1:i)]
B <- r[-(1:i)]
arrangements <- c(arrangements, apply(do.call(rbind, permn(1:length(items))), 1, function(z) list(z[A], z[B])))
}
, , , .. { 1, 2, 3} {2, 1, 3} n. - , ? .