title: Moving average with varying time window in R
body: <p>I want to compute a moving average over a certain time window without generating NAs at the beginning of the time series. For instance, if I set the time window to 3, the 2 first observations will have NAs. What I want is to have a time window of 1 for the first observation, 2 for the second observation, and then 3 for all the remaining observations.</p>
  
  <p>My current code:</p>
  
  <pre><code>#example data
  x &lt;- c(3,9,2,8,4,6,5,8)
  #moving average with time window of length 3
  (ma3 &lt;- filter(x,rep(1/3,3),sides=1))
  </code></pre>