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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate 
# the use of cumprod() Function
  
# Calling cumprod() Function
cumprod(1:4)
cumprod(-1:-6)

chevron_right


Output:

[1]  1  2  6 24
[1]   -1    2   -6   24 -120  720

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate 
# the use of cumprod() Function
  
# Creating Vectors
x1 <- c(2, 4, 5, 7)
x2 <- c(2.4, 5.6, 3.4)
  
# Calling cumprod() Function
cumprod(x1)
cumprod(x2)

chevron_right


Output:

[1]   2   8  40 280
[1]  2.400 13.440 45.696
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.