[R] problem with do.call

Thomas Lumley tlumley at u.washington.edu
Thu Apr 11 19:04:15 CEST 2002

On 11 Apr 2002, Ernesto Jardim wrote:

> Hi
> This was not my understanding. I thougth that if you can use functions
> like apply and similar instead of for loops your code will be faster.
> Basicly relying on these functions code which is (should be) optimized
> for speed.
> If what you're saying is true then using functions like apply is a
> matter of simplicity and not speeding up the code.
> Is this correct ?

Yes. As you can easily verify [and always should verify if you're doing
optimisation], the apply commands are rarely faster than their for() loop
equivalents. They can be slower.

The speed advantage of apply is partly mythical -- there's never been that
much advantage -- and partly historical, as in some versions of S-PLUS 3.x
apply was often faster for complicated reasons due to memory management.

The real point of the apply() family is to suppress unnecessary loop
variables and make your code tidier.  If we ever get parallel processing
then apply() could really become faster, but that's not going to happen
any time soon.


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list