Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

r
function
communitycreator

How to obtain the pairwise minimum of two or more vectors in R

Onyejiaku Theophilus Chidalu

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 (TRUE or FALSE) 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 vector
a <- c(10, 8, 3, 9, 0, 5)
b <- c(15, 4, 6, 9, 8, 4)

# obtaining the maximum values pairwise
pmin(a, b)
Implementing the pmin() function in R

Explanation

  • Line 2 and 3: We create vector objects, a and b.
  • Line 6: We obtain the minimum values in the input vector objects pairwise.

RELATED TAGS

r
function
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring