Index of the minimum or maximum value

DESCRIPTION:

Find the index of the (first) minimum or maximum value in a vector of numbers.

USAGE:

which.min(x)
which.max(x)

REQUIRED ARGUMENTS:

x
A vector of non-complex numbers. Logical data are accepted, with the usual mapping of TRUE to 1 and FALSE to 0. Missing values are silently ignored.

VALUE:

Generally a scalar integer, i, such that x[i]==max(x,na.rm=TRUE). If there are no nonmissing values in x then a zero-long integer vector is returned.

DETAILS:

This functions is written in C so it should be faster than the naive which(x==max(x,na.rm=TRUE))[1] .

SEE ALSO:

EXAMPLES:

> which.max(c(1,NA,10,5))
# [1] 3