[R] How to optimize this codes ?

Daren Tan daren76 at hotmail.com
Thu Dec 4 17:02:49 CET 2008

How to optimize the for-loop to be reasonably fast for sample.size=100000000 ? You may want to change sample.size=1000 to have an idea what I am achieving. 
A <- matrix(sample(0:1, sample.size, TRUE), ncol=10, dimnames=list(NULL, LETTERS[1:10]))
B <- list()
for(i in 1:10) { 
  B[[i]] <- apply(combn(LETTERS[1:10], i), 2, function(x) { sum(apply(data.frame(A[,x]), 1, all)) })
boxplot(B, xlab = "Number of predictors", ylab = "Number of agreements across predictors")

More information about the R-help mailing list