[R] lapply vs. for (was: Incrementing a counter in lapply)

Thomas Lumley tlumley at u.washington.edu
Wed Mar 15 23:20:00 CET 2006

On Wed, 15 Mar 2006, Philippe Grosjean wrote:

> the for() loop is very slow in S-PLUS. This is probably one of the
> motivation of developing the apply() family of functions (as well as the
> ugly For() loop) under this system.
> Now, for() loops are much faster in R. Also, if you look at the R code
> in apply(), you will realize that there is a for() loop in it!

lapply(), on the other hand, can be faster than a loop. That's why it went 
from being a loop to being internal C code.


More information about the R-help mailing list