Re: [R] applying max elementwise to two vectors

From: Afshartous, David <afshart_at_exchange.sba.miami.edu>
Date: Thu, 28 Jun 2007 17:26:53 -0400

thanks all. yes, pmax(x,y) gets it straight away. sorry for missing this
when I checked the docs.

-----Original Message-----
From: Greg Snow [mailto:Greg.Snow_at_intermountainmail.org] Sent: Thursday, June 28, 2007 5:26 PM
To: Afshartous, David; r-help_at_stat.math.ethz.ch Subject: RE: [R] applying max elementwise to two vectors

Are you looking for pmax? (look at the help ?pmax and the examples and see if that does what you want).

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_intermountainmail.org
(801) 408-8111
 
 


> -----Original Message-----
> From: r-help-bounces_at_stat.math.ethz.ch
> [mailto:r-help-bounces_at_stat.math.ethz.ch] On Behalf Of Afshartous,
> David
> Sent: Thursday, June 28, 2007 2:20 PM
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] applying max elementwise to two vectors
>
>
>
> 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
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> ______________________________________________ R-help_at_stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Thu 28 Jun 2007 - 21:59:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Jun 2007 - 22:32:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.