Skip to content
Prev 108662 / 398498 Next

Help with efficient double sum of max (X_i, Y_i) (X & Y vectors)

On Thu, 1 Feb 2007, Ravi Varadhan wrote:

            
This is the sort of problem where profiling can be useful.  My experience 
with pmax() is that it is surprisingly slow, presumably because it handles 
recycling and NAs

In the example I profiled (an MCMC calculation) it was measurably faster 
to use
    function(x,y) {i<- x<y; x[i]<-y[i]; x}

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