Reputation: 45
I am looking to generate ordered permutation for large numbers i.e. 37P10 (permutations for 37 of size 10). I am using combinat
package, permn()
function for the purpose but it does not work for more than 10 numbers. Also through this i cannot be able to generate permutation of different sizes as describe above in example.
Further, I am combining these permutation into a matrix using do.call(rbind,)
function.Is any any other package in R-language that may be used for the purpose please?
Upvotes: 1
Views: 778
Reputation: 176718
What you've asked for simply cannot be done. You're asking to generate and store 1.22e15 (or 4.81e15 with replacement) permutations of 10 numbers. Even if each number were only one byte, you would need 10 million GB of RAM.
In my LSPM package, I use the function LSPM:::.nPri
to generate a specific permutation based on its lexically ordered index. There's no way you will be able to iterate over every permutation in an reasonable amount of time, so I would suggest that you take a sample of all possible permutations.
Note that the above code will not work for nPr(37,10) due to precision issues with such a large number, but it should work as a good starting point.
Upvotes: 5
Reputation: 17189
It is near impossible to generate so many permutation on the normal computer.
Quick calculations shows (37 P 10)
is 1264020397516800
. To store this many integers itself, you would need 1264020397516800 x 64
bits. That is 8.09×10^7 Gb (gigabits)
or 10^7 Gigabytes
. Then to store actual permutation information you will need even more "memory" either in RAM or Harddisk.
I think best strategy would be to write permutation function, creates ordered permutation sequentially, and do your analysis iteratively without generating all possible permutations.
Upvotes: 3