I'm using R to generate permutations of a vector that has replicates in it.
While generating the permutations I'm using numbers to represent the groups. Here's what I can do for small ones:
unlist(unique(permn(c(1,1,2,2,3,3,4,4), paste0, collapse = "")))
Which returns a vector of 2520 permutations (8!/2^4)
The problem is I'm trying to scroll this up to 11 so that I can get every unique permutation of a 16 choose 11. In order to get every combination I do:
combs = unique(combn(c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4),11, paste0, collapse = ""))
and then would iterate through them and paste them together to get all unique 16 choose 11 permutations.
Sounds like a huge number?
It isn't. It's 525,525 rows, theoretically (16!/5!4!4!4!4!) The problem is that this method has to calculate all 174356582400 rows (that's 174 billion roughly) in groups of 39 million (11!) and do the unique operation on them.
Is there a method that shortcuts and factors in the replicates while finding the permutations?
Looking at other methods, I see that this would work:
unique(permutations(16,11, c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4), set=FALSE))
except that it spends too much time doing it, and it is doing the same thing that I'm doing above by finding all the bad ones and then uniqueing them out