How to obtain the pairwise minimum of two or more vectors in R
Overview
In R, the pmin() function is used to obtain the parallel minima of two or more given vectors. In simple words, it returns the minimum of the values of the two or more vectors pair-wise.
Syntax
pmin(..., na.rm = FALSE)
Syntax for the pmin() function in R
Parameters
This function takes the following parameter values:
...: This represents input vector objects. This parameter is required.na.rm: This takes a logical value (TRUEorFALSE) indicating if the missing values should be removed or not. This parameter is optional.
Return value
This function returns a vector with the longest of the input vectors representing the pair-wise minima of the input vectors.
Example
# creating vectora <- c(10, 8, 3, 9, 0, 5)b <- c(15, 4, 6, 9, 8, 4)# obtaining the maximum values pairwisepmin(a, b)
Explanation
- Line 2 and 3: We create vector objects,
aandb. - Line 6: We obtain the minimum values in the input vector objects pairwise.