[R] uniroot speed and vectorization?

ivo welch ivowel at gmail.com
Sat Apr 2 14:24:07 CEST 2011

curiosity---given that vector operations are so much faster than
scalar operations, would it make sense to make uniroot vectorized?  if
I read the uniroot docs correctly, uniroot() calls an external C
routine which seems to be a scalar function.  that must be slow.  I am
thinking a vectorized version would be useful for an example such as

  of <- function(x,a) ( log(x)+x+a )
  uniroot( of, c( 1e-7, 100 ), a=rnorm(1000000) )

I would have timed this, but I would have used a 'for' loop, which is
probably not the "R way" of doing this.  has someone already written a
package that does this?


Ivo Welch (ivo.welch at brown.edu, ivo.welch at gmail.com)

More information about the R-help mailing list