[R] More efficient alternative to combn()?
Sharpie
chuck at sharpsteen.net
Fri Mar 26 14:02:41 CET 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?
>
> Thanks in advance,
>
> El
>
The unique() function can be used to quickly filter out duplicates in your
input function. I am not aware of an alternative implementation of combn(),
but that doesn't mean there isn't one out there.
Good luck!
-Charlie
-----
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
--
View this message in context: http://n4.nabble.com/More-efficient-alternative-to-combn-tp1692117p1692128.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list