[R] Speeding up a loop
wwreith
reith_william at bah.com
Fri Jul 20 20:34:36 CEST 2012
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.
More information about the R-help
mailing list