max
and min
return the maximum or minimum of all
the values present in their arguments, as integer
if
all are logical
or integer
, as double
if
all are numeric, and character otherwise.If na.rm
is FALSE
an NA
value in any of the
arguments will cause a value of NA
to be returned, otherwise
NA
values are ignored.
The minimum and maximum of a numeric empty set are +Inf
and
-Inf
(in this order!) which ensures transitivity, e.g.,
min(x1, min(x2)) == min(x1, x2)
. For numeric x
max(x) == -Inf
and min(x) == +Inf
whenever length(x) == 0
(after removing missing values if
requested). However, pmax
and pmin
return
NA
if all the parallel elements are NA
even for
na.rm = TRUE
.
pmax
and pmin
take one or more vectors (or matrices) as
arguments and return a single vector giving the ‘parallel’
maxima (or minima) of the vectors. The first element of the result is
the maximum (minimum) of the first elements of all the arguments, the
second element of the result is the maximum (minimum) of the second
elements of all the arguments and so on. Shorter inputs (of non-zero
length) are recycled if necessary. Attributes (see
attributes
: such as names
or
dim
) are copied from the first argument (if applicable,
e.g., not for an S4
object).
pmax.int
and pmin.int
are faster internal versions only
used when all arguments are atomic vectors and there are no classes:
they drop all attributes. (Note that all versions fail for raw and
complex vectors since these have no ordering.)
max
and min
are generic functions: methods can be
defined for them individually or via the
Summary
group generic. For this to
work properly, the arguments …
should be unnamed, and
dispatch is on the first argument.
By definition the min/max of a numeric vector containing an NaN
is NaN
, except that the min/max of any vector containing an
NA
is NA
even if it also contains an NaN
.
Note that max(NA, Inf) == NA
even though the maximum would be
Inf
whatever the missing value actually is.
Character versions are sorted lexicographically, and this depends on
the collating sequence of the locale in use: the help for
‘Comparison’ gives details. The max/min of an empty
character vector is defined to be character NA
. (One could
argue that as ""
is the smallest character element, the maximum
should be ""
, but there is no obvious candidate for the
minimum.)