Suppose I have a vector x
as:
x <- c(X1, X2, X3, ..., Xn)
I want to write a function that automatically get the result series like this:
y <- c(X1, X1*X2, X1*X2*X3, ..., X1*X2*X3*...*Xn)
Can someone tell me how to do this in R?
Have a look at ?cumprod
:
cumprod(1:10)
# [1] 1 2 6 24 120 720 5040 40320 362880 3628800
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With