On 17-Apr-10 23:14:32, Mark Na wrote:
> Hello,
> I have two vectors of length = 10
> 
> x<-c(2,14,79,27,3,126,15,1,12,4)
> y<-rep(4,10)
> 
> and I would like to create a third vector of length = 10 that
> contains the smallest value at each position in the two above vectors.
> 
> I have tried:
> 
> z<-min(x,y)
> 
> but that doesn't work.
> 
> With the example data above, the third vector would look like this.
> 
>> z
>  [1]   2  4  4  4   3 4  4   1  4   4
> 
> Any help with this would be much appreciated, thanks!
> 
> mark

What you need is pmin()

>From ?min :
   'max' and 'min' return the maximum or minimum of _all_ the
    values present in their arguments

Note "all": in other words, your min(x,y) is equivalent to

  min(c(2,14,79,27,3,126,15,1,12,4,4,4,4,4,4,4,4,4,4,4))

(which = 1).

Further from ?min :

  'pmax' and 'pmin take one or more vectors (or matrices)
  as arguments and return a single vector giving the
  'parallel' maxima (or minima) of the vectors. The first
  element of the result is the maximum (minimum) of the
  first elements of all the arguments, the second element of
  the result is the maximum (minimum) of the second elements
  of all the arguments and so on.

Hence pmin() ("p" for "parallel").

Ted.




--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 18-Apr-10                                       Time: 00:28:16
------------------------------ XFMail ------------------------------

______________________________________________
R-help@r-project.org 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.

Reply via email to