VOOZH about

URL: https://www.geeksforgeeks.org/r-language/calculate-cumulative-sum-of-a-numeric-object-in-r-programming-cumsum-function/

⇱ Calculate Cumulative Sum of a Numeric Object in R Programming - cumsum() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Calculate Cumulative Sum of a Numeric Object in R Programming - cumsum() Function

Last Updated : 15 Jul, 2025

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: 

Output:

[1] 1 3 6 10
[1] -1 -3 -6 -10 -15 -21

Example 2: 

Output:

[1] 2 6 11 18
[1] 2.4 8.0 11.4
Comment

Explore