title: Cumulative sum of multiple rasters in R
body: <p>I have 200 rasters with air temperatures for each day stored in a directory and I would like to do a cumulative sum of temperatures for each day, e.g. 
  day1 = day1; day2 = day1 + day2; day3 = day1 + day2 + day3, etc.
  I tried to do it in <code>raster</code> package, but the <code>cumsum</code> function calculates the cumulative sum of all cells in each raster and not the cumulative sum of individual rasters (at least it seems to me from my results).
  I tried to do it like this: </p>
  
  <pre><code>library(raster)
  
  setwd("C:/Air_temperatures/AT") # set working directory
  
  AT.files &lt;- list.files(pattern="AT") # list files with name AT
  All.AT &lt;- unique(AT.files) # unique files
    for (i in 1:200) {
      AT.i &lt;- All.AT[i] # make i
      AT.raster.i&lt;-raster(AT.i) # make rasters from files
      AT.sum.i &lt;- cumsum(AT.raster.i) # ???calculate cumulative sum???
      writeRaster(AT.sum.i,
                 paste(AT.i, "_cumsum.tif", sep = ""),
                datatype='FLT4S', overwrite=TRUE) # write new files and paste new name
    } 
  </code></pre>
  
  <p>This loop worked when I tried for example to add a constant to each raster and so on, but I have no idea how to calculate the cumulative sum.</p>