That is faster than what I was doing and reducing 15% of my iterations it still very helpful.
Next question. I need to multiply each row x[i,] of the matrix x by another matrix A. Specifically for(i in 1:n) { If (x[i,]%*%A[,1]<.5 || x[i,]%*%A[,2]<42 || x[i,]%*%A[,3]>150) { x<-x[-i,] n<-n-1 }. #In other words remove row i from x if it does not meet criteria (>=.5, >=42, <=150). When multiplied to A } Is there a better way than using a for loop for this or x<-x[-i,] for that matter? I assume building a new matrix would be worse. Ideally I want to also exclude some x[,i] as well example if x[1,] is better than x[2,] in all three categories i.e. bigger, bigger, and smaller than x[2,] when multiplied to A then I want to exclude x[2,] as well. Any suggestions on whether it is better to do this all at once or in stages? Thanks for helping! -- View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637255.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.