Skip to content
Prev 109171 / 398500 Next

Timings of function execution in R [was Re: R in Industry]

On 2/9/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
I had an example just last month of an MCMC calculation where profiling showed that pmax(x,0) was taking about 30% of the total time.  I used

     function(x) {z <- x<0; x[z] <- 0; x}

which was significantly faster. I didn't try the arithmetic solution. Also, I didn't check if a solution like this would still be faster when both arguments are vectors (but there was a recent mailing list thread where someone else did).


      -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle