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:
Python3
cumsum( 1 : 4 )
cumsum( - 1 : - 6 )
|
Output:
[1] 1 3 6 10
[1] -1 -3 -6 -10 -15 -21
Example 2:
Python3
x1 < - c( 2 , 4 , 5 , 7 )
x2 < - c( 2.4 , 5.6 , 3.4 )
cumsum(x1)
cumsum(x2)
|
Output:
[1] 2 6 11 18
[1] 2.4 8.0 11.4
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
12 Apr, 2022
Like Article
Save Article