I am working with the combinations function (available in the gtools package). However, rather than store all of the possible combinations I would like to check each combination to see if it meets a certain criteria. If it does, I will then store it. I have looked at the combinations code but am unsure where in the algorithm I would be able to operate on each combination. Thanks! [[alternative HTML version deleted]]
I think there are several packages that implement combinations and several that allow you to specify a function to be called when each vector of combinations is generated. I can't recall the names of all such packages, but the Combinations package on www.omegahat.org/Combinations is one. D. Herm Walsh wrote:> I am working with the combinations function (available in the gtools package). However, rather than store all of the possible combinations I would like to check each combination to see if it meets a certain criteria. If it does, I will then store it. > > I have looked at the combinations code but am unsure where in the algorithm I would be able to operate on each combination. > > Thanks! > > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > 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.
On Mar 2, 2010, at 9:15 PM, Herm Walsh wrote:> I am working with the combinations function (available in the gtools > package). However, rather than store all of the possible > combinations I would like to check each combination to see if it > meets a certain criteria. If it does, I will then store it. > > I have looked at the combinations code but am unsure where in the > algorithm I would be able to operate on each combination.Logical indexing: > combinations(3,2,letters[1:3])[,1]=="a" [1] TRUE TRUE FALSE > combinations(3,2,letters[1:3])[ combinations(3,2,letters[1:3])[, 1]=="a", ] [,1] [,2] [1,] "a" "b" [2,] "a" "c" -- David Winsemius.