Skip to content
Prev 307597 / 398513 Next

practical to loop over 2million rows?

On Oct 10, 2012, at 1:31 PM, Jay Rice wrote:

            
You should describe what you want to do and you should learn to use the vectorized capabilities of R  and leave the for-loops for process that really need them
Instead :

y[!is.na(x)] <- x[!is.na(x)]  # No loop.
When you index outside the range of the length of x you get NA as a result. Furthermore you are setting y to be only a single element. So I think 'y' will be a single NA at the end of all this.
[1] 1 1 2 2 1 2 2 2 2 1
[1] NA

 There is no implicit indexing of the LHS of an assignment operation. How long is strataID? And why not do this inside a dataframe?
You will gain efficiency when you learn vectorization. And when you learn to test your code for correct behavior.
David Winsemius, MD
Alameda, CA, USA