Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
r
communitycreator

What is the cummax() 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.

Which

Overview

The cummax() function in R obtains the vector's maximum for each index in the vector starting from the beginning of the vector up to the current index.

Syntax

Here is the syntax of the cummax() method:

cunmax(x)
The syntax for the cummax() function

Parameter value

The cummax() function takes a single parameter value, x, which represents a numerical or integer vector.

Example

This is the code for the cummax()method:

# implementing the cummax() function
cummax(1:10)
cummax(c(1, 3, 4, 5, 3, 2, 5, 1, 7, 8, 8, 6))
cummax(c(3, 2, 4, 6, 2, 6, 7, 1, 6, 8, 1, 2))
cummax(c(20, 10, 5, 30, 50, 60, 15, 15))
Implementing the cummax() function

Explanation

  • Line 2: We implement the cummax() to return a vector object where its maximum elements should start with 1. This is because 1 is the element in the vector object's first index.
  • Line 3: We implement the cummax() function to return a vector object where its maximum elements should start with 1. This is because 1 is the element in the vector object's first index.
  • Line 4: We implement the cummax() function to return a vector object where its maximum elements should start with 3 . This is because 3 is the element in the vector object's first index.
  • Line 5: We implement the cummax() function to return a vector object where its maximum elements should start with 20. This is because 20 is the element in the vector object's first index.

    RELATED TAGS

    function
    r
    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