[R] How to write efficient R code

Thomas Lumley tlumley at u.washington.edu
Tue Feb 17 23:19:49 CET 2004

On Wed, 18 Feb 2004, Ko-Kang Kevin Wang wrote:
> One way to make your codes more efficient is to use "vectorisation" --
> vectorise your codes.  I'm not sure where you can find more
> information about it, but an example would be to use the apply()
> function on a data frame instead using a loop.  Avoid loops if you
> can.

Umm. No.  Vectorization is definitely a good thing -- just about the only
coding change that improves both clarity and speed -- but replacing a loop
with apply() is not vectorisation in that sense.

Except for some cases of lapply, the apply functions are mostly clarity
optimisations rather than speed optimisations.


More information about the R-help mailing list