title: Rolling mean every five months over three months
body: <p>I would like to calculate rolling means, with the following specifications:</p>
  
  <ul>
  <li>Start at the end of a given month, e.g. May</li>
  <li>Use (daily) data from the last three months to calculate the mean over this period</li>
  <li>Note: there can be missing values for some dates in a particular month and the number of days per months can vary, which makes the number of observations per calculation generally variable</li>
  <li>Repeat this calculation by going forward 5 months, e.g. if in May was the last calculation, at the end of October, etc., so that the window is sliding by every 5 months and uses data for the last 3 respectively available months [Assuming data starts in March 2018, the first window would be: March-April-May 18, then Aug-Sept-Oct 18, etc.]</li>
  <li>the size of the dataset/memory is important to me, as my real dataset is quite large</li>
  </ul>
  
  <p>I searched a long time but I didn't find any clear solution, when the <code>width</code> parameter is variable and the window is sliding. I am especially looking for a solution in <code>zoo</code>. Also <code>datatable</code> and <code>plyr</code> (or <code>xts</code>) would be interesting for completion. </p>
  
  <p>Sample data (note: There are no missing values here, because I cannot delete rows in datatable easily)</p>
  
  <pre><code>set.seed(44)  
  dataset &lt;- data.table(ID=c(rep("A",2208),rep("B",2208)),
  x = c(rnorm(2208*2)), time=c(seq(as.Date("1988/03/15"),
  as.Date("2000/04/16"), "day"),seq(as.Date("1988/03/15"),
  as.Date("2000/04/16"), "day")))
  </code></pre>
  
  <p>The dataset contains data points 'x' for 2 individuals, A and B, which can be used to calculate the mean.</p>