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 -- View this message in context: n4.nabble.com/More-efficient-alternative-to-combn-tp1692117p1692117.html Sent from the R help mailing list archive at Nabble.com.
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: n4.nabble.com/More-efficient-alternative-to-combn-tp1692117p1692128.html Sent from the R help mailing list archive at Nabble.com.
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: 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 > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide 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 famprevmed.ucsd.edu/faculty/cberry La Jolla, San Diego 92093-0901