What is a "good" way to calculate the "moving product", for each row of a dataframe, where I wish to be able to specify the length of the moving product? Depending on my needs, I'd like to be able to specify the "length" over which to calculate the moving average (in this example, length=3).

For example, if I have a dataframe with 20 rows and 6 columns, and I wish to calculate the moving product across a "length" of 3 columns.



e.g.
mydata <- data.frame(matrix(seq(20*6), 20, 6))
mydata[1,] 

#  X1 X2 X3 X4 X5  X6
#1  1 21 41 61 81 101

#I'd like to return a dataframe that has the same dimensions as mydata.
#e.g. This is what I'd want for the first row:
#NA NA 861 52521 202581 499041


      
	[[alternative HTML version deleted]]

