[R] how to speed up this for loop?

Rheannon rbrooks at uvic.ca
Tue Jul 22 01:24:05 CEST 2008


Could anyone tell me a better way to achieve the output of this for loop? It
seems to run quite slow. I'm sure there must be a more consise way to sum
from FN to LN, excluding positive values, for each row.

#sum between FN and LN, excluding positive values
for(i in 1:R){
for(j in FN[i]:LN[i]){
if(Temp[i,j]<0)
sum[i] <- sum[i] + sum(Temp[i,j])}}

Cheers, 
R
-- 
View this message in context: http://www.nabble.com/how-to-speed-up-this-for-loop--tp18579577p18579577.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list