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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.