Learn R Programming

rv (version 0.949)

Extremes.rv: Maxima and Minima of (Random and Non-Random) Vectors

Description

Returns the (parallel) maxima and minima of the input values.

Usage

max(..., na.rm=FALSE)
  min(..., na.rm=FALSE)  pmax(..., na.rm=FALSE)
  pmin(..., na.rm=FALSE)

Arguments

...
numeric or random (rv) arguments.
na.rm
a logical indicating whether missing values should be removed.

Value

  • max and min return the maximum or minimum of all the values present in their arguments, as integer if all are integer, or as double otherwise.

    The minimum and maximum of an empty set are +Inf and -Inf (in this order!) which ensures transitivity, e.g., min(x1, min(x2)) == min(x1,x2). In Rversions before 1.5, min(integer(0)) == .Machine$integer.max, and analogously for max, preserving argument type, whereas from Rversion 1.5.0, max(x) == -Inf and min(x) == +Inf whenever length(x) == 0 (after removing missing values if requested).

    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.

    pmax and pmin take several 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 vectors are recycled if necessary. If na.rm is FALSE, NA values in the input vectors will produce NA values in the output. If na.rm is TRUE, NA values are ignored. attributes (such as names or dim) are transferred from the first argument (if applicable).

    max and min are generic functions: methods can be defined for them individually or via the Summary group generic.

References

Kerman, Jouni and Gelman, Andrew. Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Technical report, Columbia University, New York.

See Also

range (both min and max)

Examples

Run this code
require(stats)
 x <- rpois(n=5, lambda=2)
 min(x, 1)  #-> one rv
 pmin(x, 1) #->  5  rvs

x <- sort(rnorm(100));  cH <- 1.35
pmin(cH, quantile(x)) # no names
pmin(quantile(x), cH) # has names
plot(x, pmin(cH, pmax(-cH, x)), type='b', main= "Huber's function")

Run the code above in your browser using DataLab