[R] Speeding up a loop
reith_william at bah.com
Sat Jul 21 14:26:38 CEST 2012
next for loop question.
I need a loop that removes a row from a matrix if it is worse in positions
1,2,3,4 than another row in the matrix. right now my matrix is 503028x26.
Rule to define worse position1 is smaller, position2 is smaller, position3
is higher, and position4 is smaller
row1: 1, 10, 3, 3
row2: 3, 7, 5, 2
row2 is not worse than row1 since it is "better" in position 1, eventhough
it is worse in all other positions.
row3 however is worse than row2 and should be removed from the matrix.
Any ideas? Should I break this into pieces or do it all at once? Is there
something faster than a loop? My current loops takes well over 24 hours to
for(i in 1:n)
if(a>m[j,1] && a>m[j,2] && a>m[j,4] && a<m[j,4])
} else j<-j+1
if(a>min(m[,1]) || a>min(m[,3]) || a>min(m[,4]) ||
View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637305.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help