[R] problem with do.call

Thomas Lumley tlumley at u.washington.edu
Wed Apr 10 18:41:30 CEST 2002


On 10 Apr 2002, Ernesto Jardim wrote:
>
> define "vectorize function"
>

Many R functions can operate on a vector of parameter values, eg

log(10,c(2,e,10)) gives the log of 10 to base 2, e, and 10

If your function can do this, you can construct a set of vectors
containing all your parameter values (expand.grid() is useful for this)
and evaluate your function once.

This can be faster than for() loops when much of the iteration is done in
compiled code.  If the iteration has to be done in interpreted code then
you can't really speed up the for() loops.  You can hide the loops with
the apply() functions, which may make your code more readable, but it
won't typically speed it up.


	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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