which.pmax {omnibus} | R Documentation |
Which vector has maximum value at each element
Description
These functions are vectorized versions of which.max
and which.min
, which return the index of the value that is maximum or minimum (or the first maximum/minimum value, if there is a tie). In this case, the function is supplied two or more vectors of the same length. For each element at the same position (e.g., the first element in each vector, then the second element, etc.) the function returns an integer indicating which vector has the highest or lowest value (or the index of the first vector with the highest or lowest value in case of ties).
Usage
which.pmax(..., na.rm = TRUE)
which.pmin(..., na.rm = TRUE)
Arguments
... |
Two or more vectors. If lengths do not match, the results will likely be be unanticipated. |
na.rm |
Logical, if |
Value
Vector the same length as the input, with numeric values indicating which vector has the highest value at that position. In case of ties, the index of the first vector is returned.
Functions
-
which.pmin()
: Which vector has minimum value at each element
See Also
which.max
, which.min
, pmax
, pmin
Examples
set.seed(123)
a <- sample(9, 5)
b <- sample(9, 5)
c <- sample(9, 5)
a[2:3] <- NA
b[3] <- NA
a[6] <- NA
b[6] <- NA
c[6] <- NA
which.pmax(a, b, c)
which.pmin(a, b, c)
which.pmax(a, b, c, na.rm=FALSE)
which.pmin(a, b, c, na.rm=FALSE)