[R] Performance note: Preallocating helps? and two questions

Angelo Canty canty at cicma.concordia.ca
Wed Nov 1 16:53:44 CET 2000


I'm not sure why the first method works so badly although it is
clearly not something you should do.  You are trying to use indices
of 1:35833 on a vector of length 1.  With the second method the vector
that you are using is at least of the correct length.  On my Sun Sparc
the first method takes 3 minutes and the second takes 9 seconds.
Interestingly on S-plus 3.4 for Unix, the two methods take about the
same time (12 seconds each).  My personal feeling is that the first
method should result in an error message (or at least a warning).

In any case there is no need for a loop here since
AUcap30 <- pmin(AU, 30)
does what you want in about half a second.

Angelo

Bob Sandefur wrote:
> 
> hi-
>  in r 1.1 on windows 2000
>  with length(AU) of 35833
>  AUcap30<-0
>  for(i in 1:length(AU))AUcap30[i]<-min(30,AU[i])
> took over an hour on pentium II 300 mhertz (I esc'ed before it finished)
> but
> AUcap30<-AU
>  for(i in 1:length(AU))AUcap30[i]<-min(30,AU[i])
> is very quick (a few seconds)
> 
> Is this performance difference common in r (ie is linux the same way)?
> 
> Are there other tricks to speed up R (in windows) (besides a faster processor and more memory)?
> 
> thanx
> 
> bob sandefur
> 
> Principal Geostatistician
> Pincock Allen & Holt
> International Minerals Consultants
> 274 Union Suite 200
> Lakewood CO 80228
> USA
> 303 914-4467  v
> 303 987-8907 f
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
****************************************************
**   Angelo J. Canty                              **
**   Dept of Mathematics and Statistics           **
**   Concordia University                         **
**   Montreal, Quebec.                            **
**                                                **
**   Tel :  +1-514-848-3244                       **
**   Fax :  +1-514-848-4511                       **
**   Email : canty at discrete.concordia.ca          **
****************************************************
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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