Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Calculate Cumulative Product of a Numeric Object in R Programming – cumprod() Function
Next article icon

Calculate the Cumulative Maxima of a Vector in R Programming - cummax() Function

Last Updated : 11 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The cumulative maxima is the max value of elements 1 through l for an element l of the given variables.

cummax() function in R Language is used to calculate the cumulative maxima of the values of vector passed as arguments.

Syntax: cummax(x) 

Parameters: 

x: numeric object

Example 1: 

Python3
# R program to cumulative maxima  # Calling cummax() function cummax(6:2) cummax(-2:-6) cummax(3.8:1.2) 

Output:

[1] 6 6 6 6 6 [1] -2 -2 -2 -2 -2 [1] 3.8 3.8 3.8

Example 2: 

Python3
# R program to cumulative maxima  # Creating vectors x1 <- c(5, 3, 2, 6, 3, 4) x2 <- c(-4, 6, 3)  # Calling cummax() function cummax(x1) cummax(x2) 

Output:

[1] 5 5 5 6 6 6 [1] -4  6  6

Since, the maxima is calculated for the values in decreasing order and hence the above code shows two cumulative values for vectors.

Example :

the example of how to calculate the cumulative maxima of a vector in R using the cummax() function.

R
# Create a sample vector v <- c(1, 6, 2, 7, 5, 9)  # Calculate the cumulative maxima of the vector cumulative_max <- cummax(v)  # Print the results print(cumulative_max) 

output :

[1] 1 6 6 7 7 9

Next Article
Calculate Cumulative Product of a Numeric Object in R Programming – cumprod() Function

N

nidhi_biet
Improve
Article Tags :
  • R Language
  • R Vector-Function

Similar Reads

  • Calculate the Cumulative Minima of a Vector in R Programming - cummin() Function
    cummin() function in R Language is used to calculate the cumulative minima of the values of vector passed as arguments. Syntax: cummin(x) Parameters: x: numeric object Example 1: # R program to cumulative minima # Calling cummin() function cummin(2:6) cummin(-2:-6) cummin(1.8:4.2) Output: [1] 2 2 2
    1 min read
  • Calculate Cumulative Sum of a Numeric Object in R Programming - cumsum() Function
    The cumulative sum can be defined as the sum of a set of numbers as the sum value grows with the sequence of numbers. cumsum() function in R Language is used to calculate the cumulative sum of the vector passed as argument. Syntax: cumsum(x)  Parameters:  x: Numeric Object Example 1:  [GFGTABS] Pyth
    1 min read
  • Calculate Cumulative Product of a Numeric Object in R Programming – cumprod() Function
    cumprod() function in R Language is used to calculate the cumulative product of the vector passed as argument. Syntax: cumprod(x) Parameters: x: Numeric Object Example 1: # R program to illustrate # the use of cumprod() Function # Calling cumprod() Function cumprod(1:4) cumprod(-1:-6) Output: [1] 1
    1 min read
  • Calculate the Sum of Matrix or Array columns in R Programming - colSums() Function
    colSums() function in R Language is used to compute the sums of matrix or array columns. Syntax: colSums (x, na.rm = FALSE, dims = 1) Parameters: x: matrix or array dims: this is integer value whose dimensions are regarded as ‘columns’ to sum over. It is over dimensions 1:dims. Example 1: # R progra
    2 min read
  • Calculate the Mean of each Column of a Matrix or Array in R Programming - colMeans() Function
    colMeans() function in R Language is used to compute the mean of each column of a matrix or array. Syntax: colMeans(x, dims = 1) Parameters: x: array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame dims: integer value, which dimensions are r
    2 min read
  • Calculate Rank of the Values of a Vector in R Programming - rank() Function
    rank() function in R Language is used to return the sample ranks of the values of a vector. Equal values and missing values are handled in multiple ways. Syntax: rank(x, na.last) Parameters: x: numeric, complex, character, and logical vector na.last: Boolean Value to remove NAs Example 1: # R progra
    1 min read
  • Combine Arguments into a Vector in R Programming - c() Function
    c() function in R Language is used to combine the arguments passed to it. Syntax: c(...) Parameters: ...: arguments to be combined Example 1: # R program to cumulative maxima # Calling c() function x <- c(1, 2, 3, 4) x Output: [1] 1 2 3 4 Example 2: # R program to cumulative maxima # Calling c()
    1 min read
  • Get the Minimum and Maximum element of a Vector in R Programming - range() Function
    range() function in R Programming Language is used to get the minimum and maximum values of the vector passed to it as an argument. Syntax: range(x, na.rm, finite) Parameters:  x: Numeric Vectorna.rm: Boolean value to remove NAfinite: Boolean value to exclude non-finite elementsR - range() Function
    1 min read
  • Compute the Cumulative Poisson Density in R Programming - ppois() Function
    ppois() function in R Language is used to compute the cumulative density function for Poisson distribution. Syntax: ppois(vec, lambda) Parameters: vec: Sequence of integer values lambda: Average number of events per interval Example 1: # R program to compute # Cumulative Poisson Density # Sequence o
    1 min read
  • Calculate the difference between Consecutive pair of Elements of a Vector in R Programming - diff() Function
    diff() function in R Language is used to find the difference between each consecutive pair of elements of a vector. Syntax: diff(x, lag, differences) Parameters: x: vector or matrix lag: period between elements differences: Order of difference Example 1: # R program to find the difference # between
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences