Possible Duplicate:
Calculating moving average in R
I have written a rate of change function in R, defined as:
rateChange <- function(x) ((last(x)-first(x))/first(x))*100
It works wonderfully on various date ranges, such as the rate of change for 5 days, 10 days, 200 days, etc. However, I now have need to apply this function between every day. For example, to identify the rate of change for 5 days one would require the past 6 data observations.
Here is an example in Excel, and for clarity, I am trying to reproduce the "Rate of Change" column:
Thank you!