[R] for loop Vs apply function Vs foreach (REvolution enhancement)

Liviu Andronic landronimirc at gmail.com
Tue Feb 16 16:24:55 CET 2010


Hello

On 2/16/10, julien cuisinier <j_cuisinier at hotmail.com> wrote:
>  1. apply Vs for loop
>
>  >> Seems apply is (was?) supposed to be faster than using for loop, some posts mention that it is now more of a cosmetic function (wrapper for "for loop") making the code essentially neater. Any thoughts/opinion/experience on this more than welcome.
>
>  >> Running the very simple function attached, I end up with for loop quicker than apply function....but may be do I not use the apply function properly?
>
Check this [1] for a discussion of vectorisation vs looping. It seems
that vectorisation is not always better than looping.
Liviu

[1] http://www.r-project.org/doc/Rnews/Rnews_2008-1.pdf



More information about the R-help mailing list