title: Moving average with changing period in R
body: <p>I have a data frame named abc on which I'm doing moving average using <code>rollapply</code>. The following code works:</p>
  
  <p><code>forecast &lt;- rollapply(abc, width=12, FUN=mean, align = "right", fill=NA)</code></p>
  
  <p>Now, I want to do the same thing with the width being variable, i.e. for the 1st month, it'll be empty, for the second month, first month's value will come. For the third month, it'll be (first month+second month/2), i.e. for the ith month, if <code>i&lt;=12</code>, the value will be <code>(sum(1:i-1)/(i-1))</code> and for <code>i&gt;=12</code> it will be the average of the last 12 months as done by the <code>forecast</code>. Please help.</p>