Hey Mark,

I am sure there are other ways but one way would be:

data <- cbind(x,y) #put the two vectors in a matrix

> apply(data, 1, min) # use apply() to apply min() to each row
 [1] 2 4 4 4 3 4 4 1 4 4


Best regards,

Josh
On Sat, Apr 17, 2010 at 4:14 PM, Mark Na <mtb954@gmail.com> 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
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

	[[alternative HTML version deleted]]

