Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

r
pmax
communitycreator

What is the pmax() function in R?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

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.

Syntax

pmax(..., na.rm = FALSE)
Syntax for the pmax() function in R

Parameters

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.

Return value

The pmax() function returns a vector with the longest of the input vectors representing the pair-wise maxima of the input vectors.

Example

# Creating a vector
a <- c(10, 8, 3, 9, 0, 5)
b <- c(15, 4, 6, 9, 8, 4)
# Obtaining the maximum values pair-wise
pmax(a, b)
Implementing the pmax() function in R

Explanation

  • Lines 2–3: We create vector objects a and b.
  • Line 6: We call the pmax() function and pass our input vectors (a and b) to it. The function returns our desired vector (The maximum values from each pairing).

RELATED TAGS

r
pmax
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring