Skip to content
Prev 301041 / 398503 Next

[External] Re: Speeding up a loop

Hello,

Are you sure? With a matirx composed of those two rows only I had a 
problem, the function to.keep() returned NULL. See the changes made to 
avoid it.

# beginning of loop
     for(i in seq_len(nrow(x))){
         #yes <- x[i, 1] > a1 | x[i, 2] > a2 | x[i, 3] < a3 | x[i, 4] > a4
         #if(all(yes)) keep(i, e)
         # Original post, do NOT remove if equal
         #no <- x[i, 1] < a1 | x[i, 2] < a2 | x[i, 3] > a3 | x[i, 4] < a4
         # Changed to remove if equal
         no <- x[i, 1] <= a1 | x[i, 2] <= a2 | x[i, 3] >= a3 | x[i, 4] <= a4
         if(all(!no)) keep(i, e)
     }
     if(e$ires == 0 && nrow(x) > 0)
         x[1, ]
     else
         e$result[seq_len(e$ires), 1:nc]
# end of function


Em 23-07-2012 18:18, Reith, William [USA] escreveu: