Q:

Multiply row value to all previous row values in R

How would one go about to multiply a value of a row by all previous values of that row, for all rows? 
set.seed(111)

df <- data.frame(as=sample(10))

   as new

1   6   6
2   7  35
3   3  105
4   4  420
5   8  3360
6  10  33600
7   1  33600
8   2  67200
9   9  604800
10  5  3024000

I can multiply a row value with its previous one by using:
df$new <- with(df, c(as[1],as[-1]*as[-nrow(df)]))

How can i multiply a row with all previous row values for all [i]?

A:

Are you looking for cumprod?
df$new <- cumprod(df$as)
df
#    as     new
# 1   6       6
# 2   7      42
# 3   3     126
# 4   4     504
# 5   8    4032
# 6  10   40320
# 7   1   40320
# 8   2   80640
# 9   9  725760
# 10  5 3628800

