% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/which.r
\name{whichMin}
\alias{whichMin}
\alias{whichMax}
\alias{whichMin<-}
\alias{whichMax<-}
\title{Where is the min or max?}
\usage{
whichMin(x, loc = c("first", "last", "all"))

whichMax(x, loc = c("first", "last", "all"))

whichMin(x, loc = c("first", "last", "all")) <- value

whichMax(x, loc = c("first", "last", "all")) <- value
}
\arguments{
\item{x}{numeric (logical, integer or double) vector or an \strong{R}
object for which the internal coercion to \link{double} works whose \link{min}
or \link{max} is searched for.}

\item{loc}{\code{'first'}, \code{'last'} or \code{'all'} to specify which
index/indices to return.}

\item{value}{value/s to replace the min or max values with when
using the assignment functions.}
}
\value{
integer of indices. For the assignment functions, the
modified object with min or max values replaced by \code{value}.
}
\description{
Determines the location (i.e., index) of the (first, last, or all)
minima or maxima of a numeric (or logical) vector.
}
\note{
For \code{logical} vectors, \code{which(x)} is faster than
\code{whichMax(x, loc = "all")}, but \code{whichMin(x, loc = "all")} can
be faster than \code{which(!x)} for medium to large vectors due to
not having the performance cost of negating the vector.
}
\examples{
x <- c(1:4, 0:5, 11, 1:4, 0:5, 11)
whichMin(x)
whichMin(x, loc = "last")
whichMax(x)
whichMax(x, loc = "all")

# it *does* work with NA's present, by discarding them:
presidents[1:30]
whichMin(presidents) # 28
whichMax(presidents) #  2

# Find the first occurrence, i.e. the first TRUE, if there is at least one:
x <- rpois(10000, lambda = 10)
x[sample.int(50, 20)] <- NA
# where is the first value >= 20 ?
whichMax(x >= 20)
whichMax(x >= 20, loc = "last")
whichMax(x >= 20, loc = "all")

# objects are coerced to numeric vectors if possible:
whichMin(list(A = 7, pi = pi)) ##  ->  c(pi = 2L)

x <- 1:4
whichMin(x) <- 999
whichMax(x) <- -999
x
}
\seealso{
\link{which}, \link{which.max} and \link{which.min}
}
