+3 votes
in Programming Languages by (17.9k points)
Using two vectors, I want to generate a third vector that should have pairwise maximum values from two vectors. Is there any R function to find the pairwise minimum and maximum from two vectors?

E.g.

 a = c(10,1,2,31,41,14,15)

 b = c(11,0,5,32,40,12,19)

Result for max = 11  1  5 32 41 14 19

1 Answer

0 votes
by (31.2k points)

You can use the pmin() function to find the pairwise minimum value in two vectors.

To find the pairwise maximum, you can use the pmax() function.

Example:

> a = c(10,1,2,31,41,14,15)
> b = c(11,0,5,32,40,12,19)
> pmin(a,b)
[1] 10  0  2 31 40 12 15
> pmax(a,b)
[1] 11  1  5 32 41 14 19

...