which.pmax | R Documentation |
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).
which.pmax(..., na.rm = TRUE)
which.pmin(..., na.rm = TRUE)
... |
Two or more vectors. If lengths do not match, the results will likely be be unanticipated. |
na.rm |
Logical, if |
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.
which.pmin()
: Which vector has minimum value at each element
which.max
, which.min
, pmax
, pmin
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.