[R] More efficient alternative to combn()?

Charles C. Berry cberry at tajo.ucsd.edu
Fri Mar 26 18:26:01 CET 2010


On Fri, 26 Mar 2010, elgorgonzola wrote:

>
> Hi,
>
> i am working on a problem where i need to compute the products of all
> possible combinations of size m of the elements of a vector. I know that
> this can be achieved using the function combn(), e.g.:
>
>> vector <- 1:6
>> combn(x = vector, m = 3, FUN = function(y) prod(y))
>
> In my case the vector has 2000 elements and i need to compute the values
> specified above for m = 32. Using combn() i encounter problems for m >= 4.
> Is there any alternative to combn() that works more efficiently? Also my
> vector contains many duplicates, so there are actually only about 300
> distinct values in the vector. This reduces the number of possible
> combinations significantly. Is there any way to use this fact to reduce the
> computational cost?

It doesn't matter what the computational cost is.

Even if the problem was just to enumerate the choose(300,32) products of 
unique elements you would need more than 10^33 Gigabytes of memory to 
store the result.

Unless there is a lot more structure in your problem than you have 
described or unless some form of approximation is acceptable, it is not a 
problem you can hope to solve.

HTH,

Chuck

>
> Thanks in advance,
>
> El
> -- 
> View this message in context: http://n4.nabble.com/More-efficient-alternative-to-combn-tp1692117p1692117.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list