title: calculate median of several raster files with different extent
body: <p>I'm quite new to R and I have a problem on which I couldn't find a solution so far.
  I have a folder of 1000 raster files. I have to get the median of all rasters for each cell.</p>
  
  <p>The files contain NoData Cells (I think therefore they have different extents)
  Is there any solution to loop through the folder, adding together all files an getting the median?</p>
  
  <pre><code>Error in rep(value, times = ncell(x)) : invalid 'times' argument
  In addition: Warning message:
  In setValues(x, rep(value, times = ncell(x))) : NAs introduced by coercion
  Error in .local(x, i, j, ..., value) : 
    cannot replace values on this raster (it is too large
  </code></pre>
  
  <p>I tried with raster stack, but it doesn't work because of the different extents.<br>
  Thanks for your help.</p>