[R] Existence of non-vectorised functions

Ravi Varadhan rvaradha at jhsph.edu
Tue Nov 26 17:17:45 CET 2002


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?

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



More information about the R-help mailing list