which.pmax: Which vector has maximum value at each element

View source: R/which.pmax.r

which.pmaxR 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 FALSE and any of the vectors contains an NA or NaN, the function will return an NA. If TRUE (default), then NA will only be returned if all elements at that position are NA or NaN.

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)

adamlilith/omnibus documentation built on April 12, 2024, 8:46 p.m.