[R] Existence of non-vectorised functions

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Nov 26 18:43:29 CET 2002



Ravi Varadhan wrote:
> 
> Dear R-Group:
> 
> Recently, I ran into a problem.  I was using a function called "I.1",
> which evaluates the first-order modified Bessel function of the first
> kind, in the package "CircStats". This function is not vectorized,
> since it uses a couple of "if" conditions.  However, when I called this
> function with a vector argument, I got no error/warning messages in
> R1.5.1 (under Windows 2000). Furthermore, the results were generally
> incorect (please see the attached results).  However, if I vectorized
> it using "ifelse" everything is fine (I created a function
> called "myI.1" to do this).  I was wondering if there are functions in
> other packages, where such problems exist due to non-vectorization?

That's extremely probable. It depends on the package author and the
complexity of the problem, thus you have to check it yourself whether it
works vectorized or not, e.g. in the help files.

BTW: You might want to send your improvements of I.1() to the package
author as well (or even at first - hint, hint) ... 

Uwe Ligges


> thanks,
> Ravi.
> 
> #######################################################
> > require(CircStats)
> > I.1(1:10)
>  [1]    0.5651591    1.5906369    3.9533702    9.7594643   24.3351955
>  [6]   61.3232698  155.7162813  396.4825232 1005.2747089 2517.6347571
> > myI.1(1:10)
>  [1]    0.5651591    1.5906369    3.9533702    9.7594652   24.3356418
>  [6]   61.3419369  156.0390965  399.8731348 1030.9147087 2670.9883206
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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