which.min {base}
Description
Determines the location, i.e., index of the (first) minimum or maximum of a numeric vector.
Usage
which.min(x) which.max(x)
Values
Missing and NaN values are discarded.
an integer of length 1 or 0 (iff x has no non-NAs), giving the index of the first minimum or maximum respectively of x.
If this extremum is unique (or empty), the results are the same as (but more efficient than) which(x == min(x)) or which(x == max(x)) respectively.
See Also
Use arrayInd(), if you need array/matrix indices instead of 1D vector ones.
which.is.max in package nnet differs in breaking ties at random (and having a ‘fuzz’ in the definition of ties).
Examples
x <- c(1:4, 0:5, 11) which.min(x) which.max(x) ## it *does* work with NA's present, by discarding them: presidents[1:30] range(presidents, na.rm = TRUE) which.min(presidents) # 28 which.max(presidents) # 2
Documentation reproduced from R 3.0.1. License: GPL-2.
