The pmax()
function in R obtains the parallel maxima of two or more given vectors. In simpler words, the function compares the values of the two vectors in pairs and returns a final vector that contains the maximum values from each pair.
pmax(..., na.rm = FALSE)
The pmax()
function takes the following parameter values:
...
: This represents the vector objects. It is a required parameter.na.rm
: This takes a logical value (TRUE or FALSE) that indicates whether the function should remove missing values. It is an optional parameter.The pmax()
function returns a vector with the longest of the input vectors representing the pair-wise maxima of the input vectors.
# Creating a vectora <- c(10, 8, 3, 9, 0, 5)b <- c(15, 4, 6, 9, 8, 4)# Obtaining the maximum values pair-wisepmax(a, b)
a
and b
.pmax()
function and pass our input vectors (a
and b
) to it. The function returns our desired vector (The maximum values from each pairing).