# NOT RUN {
## 8-tuples of 1:17 w/o repetition
system.time(comboGeneral(17,8))
## 10-tuples of 1:13 w/ repetition
system.time(comboGeneral(13,10,repetition = TRUE))
## Generate some random data
set.seed(1009)
mySamp <- rnorm(75, 997, 23)
## How to use rowCap example:
## Researcher only needs 1000 7-tuples of mySamp
## such that the sum is greater than 7200.
system.time(comboGeneral(mySamp,7,FALSE,"sum",">",7200,1000))
## If you leave rowCap as NULL, it can take much longer
## (still fast enough most of the time) and in some cases
## crash your computer as the underlying code allocates
## enough space to account for every combination
## (e.g. In our example, there are choose(75, 7)
## = 1984829850 rows, 7 columns, with each cell occupying
## 8 bytes. This gives a total over 100 GB).
## (i.e. choose(75, 7)*7*8/(2^30)).
## Find 13-tuple combinations of 1:25 such
## that the mean is less than 10
system.time(myComb <- comboGeneral(25,13,FALSE,"mean","<",10))
# }
# NOT RUN {
## Alternatively, you must generate all combinations and subsequently
## subset to obtain the combinations that meet the criteria
system.time(myComb2 <- combn(25,13))
ystem.time(myCols <- which(apply(myComb2, 2, mean) < 10))
system.time(myComb2 <- myComb2[,myCols])
## Test equality with myComb above
all.equal(myComb,t(myComb2))
## Any variation is much slower
system.time(myComb2 <- combn(25,13)[,combn(25,13,mean) < 10])
# }
Run the code above in your browser using DataLab