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

Gregor GORJANC gregor.gorjanc at gmail.com
Thu Mar 16 06:36:43 CET 2006


On 3/15/06, Thomas Lumley <tlumley at u.washington.edu> wrote:
> 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.
>
>         -thomas


Thanks to all for this insights on *apply vs. for loop!

--
Lep pozdrav / With regards,
    Gregor Gorjanc

----------------------------------------------------------------------------------------------------
University of Ljubljana          PhD student
Biotechnical Faculty
Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3                            mail: gregor.gorjanc <at> bfro.uni-lj.si
SI-1230 Domzale                tel: +386 (0)1 72 17 861
Slovenia, Europe                 fax: +386 (0)1 72 17 888
----------------------------------------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
 you have no certainty until you try." Sophocles ~ 450 B.C.




More information about the R-help mailing list