Calculate Cumulative Product of a Numeric Object in R Programming – cumprod() Function
Last Updated :
05 Jun, 2020
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:
cumprod( 1 : 4 )
cumprod( - 1 : - 6 )
|
Output:
[1] 1 2 6 24
[1] -1 2 -6 24 -120 720
Example 2:
x1 < - c( 2 , 4 , 5 , 7 )
x2 < - c( 2.4 , 5.6 , 3.4 )
cumprod(x1)
cumprod(x2)
|
Output:
[1] 2 8 40 280
[1] 2.400 13.440 45.696
Share your thoughts in the comments
Please Login to comment...