[R] applying max elementwise to two vectors
    Afshartous, David 
    afshart at exchange.sba.miami.edu
       
    Thu Jun 28 22:19:39 CEST 2007
    
    
  
 
All,
Is there one liner way to obtain the max per observation for two
vectors?
I looked at apply and lapply but it seems that groundwork would have to
be done before applying either of those.  The code below does it but
seems
like overkill.
Thanks!
Dave
x = rnorm(10)
y = rnorm(10)
ind = which(x < y)
z = x
z[ind] <- y[ind]  ## z now contains the max's
    
    
More information about the R-help
mailing list