pmax
Parallel Maximum or Minimum

Description

Gives the maximum or minimum for each position in a number of vectors.

Usage

pmax(..., na.rm = FALSE)
pmin(..., na.rm = FALSE)
pmax.int(..., na.rm = FALSE)
pmin.int(..., na.rm = FALSE)

Arguments

... any number of numeric or character vectors.

Missing values (NA) are allowed.

na.rm a logical flag. If TRUE, missing values are ignored. The default is FALSE.

Details

If an element of any of the arguments is NA, the corresponding element of the result is also NA unless na.rm=TRUE.
The maximum or minimum is found of the non-missing values when na.rm=TRUE.
Note the difference between pmax, pmin and max, min. The latter two return a single element, which is the maximum or minimum of all arguments.
Value
returns a vector whose first element is the maximum (pmax) or minimum (pmin) of the first elements of the arguments, and similarly for the second element, and so on. The length of the vector is the length of the longest argument. Shorter vectors are reused cyclically.
If the first argument is the longest, then the result has the attributes of the first argument.
See Also
max, range, cummax, peaks.
Examples
x <- c(4, 19, 23, 3, 20)
y <- c(9, 24, 21, 4, NA)
z <- pmax(x, y, 5) # vector as long as larger of x and y
     # where z[i] is max of x[i], y[i], and 5

# as above but missing values are ignored z <- pmax(x, y, 5, na.rm = TRUE)

z <- pmax(c(1,2,1),c(5,1,1),c(4,0)) z # [1] 5 2 4

Package base version 6.1.1-7
Package Index