\HeaderA{which.min}{Where is the Min() or Max() ?}{which.min}
\aliasA{which.max}{which.min}{which.max}
\keyword{utilities}{which.min}
\begin{Description}\relax
Determines the location, i.e., index of the (first) minimum or maximum
of a numeric vector.
\end{Description}
\begin{Usage}
\begin{verbatim}
which.min(x)
which.max(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] numeric (integer or double) vector, whose
\code{\LinkA{min}{min}} or \code{\LinkA{max}{max}} is searched for.
\end{ldescription}
\end{Arguments}
\begin{Value}
Missing and \code{NaN} values are discarded.

an \code{\LinkA{integer}{integer}} of length 1 or 0 (iff \code{x} has no
non-\code{NA}s), giving the index of the \emph{first} minimum or
maximum respectively of \code{x}.

If this extremum is unique (or empty), the results are the same as
(but more efficient than) \code{which(x == min(x))} or
\code{which(x == max(x))} respectively.
\end{Value}
\begin{Author}\relax
Martin Maechler
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{which}{which}}, \code{\LinkA{max.col}{max.col}}, \code{\LinkA{max}{max}}, etc.

\code{\LinkA{which.is.max}{which.is.max}} in package \pkg{nnet} differs in
breaking ties at random (and having a \sQuote{fuzz} in the definition
of ties).
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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
\end{ExampleCode}
\end{Examples}

