Rev 38432 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{Extremes}\alias{max}\alias{min}\alias{pmax}\alias{pmin}\title{Maxima and Minima}\description{Returns the (parallel) maxima and minima of the input values.}\usage{max(\dots, na.rm=FALSE)min(\dots, na.rm=FALSE)pmax(\dots, na.rm=FALSE)pmin(\dots, na.rm=FALSE)}\arguments{\item{\dots}{numeric arguments (see Note).}\item{na.rm}{a logical indicating whether missing values should beremoved.}}\value{\code{max} and \code{min} return the maximum or minimum of \emph{all}the values present in their arguments, as \code{\link{integer}} ifall are \code{integer}, % and at least one is nonemptyor as \code{\link{double}} otherwise.The minimum and maximum of an empty set are \code{+Inf} and \code{-Inf}(in this order!) which ensures \emph{transitivity}, e.g.,\code{min(x1, min(x2)) == min(x1, x2)}. From \R version 1.5.0,\code{max(x) == -Inf} and \code{min(x) == +Inf} whenever\code{length(x) == 0} (after removing missing values if requested).If \code{na.rm} is \code{FALSE} an \code{NA} value in any of thearguments will cause a value of \code{NA} to be returned, otherwise\code{NA} values are ignored.\code{pmax} and \code{pmin} take several vectors (or matrices) as arguments andreturn a single vector giving the \dQuote{parallel} maxima (or minima) of thevectors. The first element of the result is the maximum (minimum) ofthe first elements of all the arguments, the second element of theresult is the maximum (minimum) of the second elements of all thearguments and so on. Shorter vectors are recycled if necessary. If\code{na.rm} is \code{FALSE}, \code{NA} values in the input vectorswill produce \code{NA} values in the output. If \code{na.rm} is\code{TRUE}, \code{NA} values are ignored.\code{\link{attributes}} (such as \code{\link{names}} or\code{\link{dim}}) are transferred from the first argument (if applicable).\code{max} and \code{min} are generic functions: methods can be definedfor them individually or via the \code{\link[base:groupGeneric]{Summary}}group generic.For this to work properly, the arguments \code{\dots} should beunnamed, and dispatch is on the first argument.By definition the min/max of any vector containing an \code{NaN} is\code{NaN}, except that the min/max of any vector containing an \code{NA}is \code{NA} even if it also contains an \code{NaN}. Note that\code{max(NA, Inf) == NA} even though the maximum would be \code{inf}whatever the missing value actually is.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole.}\note{\sQuote{Numeric} arguments are vectors of type integer and numeric,and logical (coerced to integer). For historical reasons, \code{NULL}is accepted as equivalent to \code{integer(0)}.% PR#1283}\seealso{\code{\link{range}} (\emph{both} min and max) and\code{\link{which.min}} (\code{which.max}) for the \emph{arg min},i.e., the location where an extreme value occurs.}\examples{require(stats)min(5:1, pi) #-> one numberpmin(5:1, pi) #-> 5 numbersx <- sort(rnorm(100)); cH <- 1.35pmin(cH, quantile(x)) # no namespmin(quantile(x), cH) # has namesplot(x, pmin(cH, pmax(-cH, x)), type='b', main= "Huber's function")}\keyword{univar}\keyword{arith}