Skip to content
Prev 72424 / 398498 Next

loops in R - about inefficiency

On Fri, 24 Jun 2005, Vehbi Sinan Tunalioglu wrote:

            
First please demonstrate that it does!

a <- 0
system.time(for(i in 1:1e6) a <- a+1)

takes 1 second for a million iterations and you think that is `so long'?
If you do, the technical explanation is that R is interpreted rather than 
compiled.

More likely the problem is *how* you are using loops.

The FAQ mentions reference material on how to use R efficiently and it 
would be more productive to learn to do so rather than claim it is 
inefficient.