title: Calculating mean, median and standard deviation in stack raster for different time steps
body: <p>I have a raster brick/stack (using the raster package) in R for 45 years of annual rainfall data from 1970 to 2015. I want to calculate mean, median and standard deviation for a given year e.g. 2015 using the last 5 years, 10 years, 15 years, 20 years, 30 years. 
  I want to do it from 2000 to 2015,  where this processes repeated for every year using the stacked data and save the newly derived rasters for a given year. This the example code. Any help is greatly appreciated. </p>
  
  <pre><code>raster &lt;- raster(ncol=10, nrow=10)
  raster_brick &lt;- brick( sapply(1:45, function(i) setValues(r, rnorm(ncell(r), i, 3))))
  plot(raster_brick)
  str(raster_brick)
  </code></pre>