title: How can I create raster mosaic using list of rasters?
body: <p>I need to create several raster mosaics. I'm using Package raster version 2.0-31 on a 64bits windows computer. I believe I did my homework checking through all possible blogs and asking this question to some colleagues, but still can't find a solution.</p>
  <p>The problem I have is that I can't create a mosaic if my grids are listed in a raster object. I found <a href="http://www.nceas.ucsb.edu/scicomp/usecases/createrasterimagemosaic" rel="nofollow noreferrer">this example</a> that I though I could apply, but not, I get a weird error message. The example below represents my problem:</p>
  <pre><code>r &lt;- raster()
  r1 &lt;- crop(r, extent(-10, 10, -10, 10))
  r2 &lt;- crop(r, extent(0, 20, 0, 20))
  r3 &lt;- crop(r, extent(10, 30, 10, 30))
  
  r1[] &lt;- 1:ncell(r1)
  r2[] &lt;- 1:ncell(r2)
  r3[] &lt;- 1:ncell(r3)
  rasters1 &lt;- list(r1, r2, r3)
  
  mos &lt;- mosaic(rasters1,fun=mean)
  </code></pre>
  <p>This is the error I get:</p>
  <blockquote>
  <p>Error in function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘mosaic’ for signature ‘&quot;list&quot;, &quot;missing&quot;’</p>
  </blockquote>
  <p>I also tried the function suggested in <a href="https://stat.ethz.ch/pipermail/r-sig-geo/2010-March/007941.html" rel="nofollow noreferrer">here</a>, but didn't work either.</p>
  <pre><code>fmerge &lt;- function(rasters1, fun, ...){
    ex &lt;- raster(union(rasters1))
    res(ex) &lt;- res(rasters1[[1]])
    for( i in 1:length(rasters1) )
      rasters[[i]] &lt;- merge(rasters1[[i]], ex)
    rasters &lt;- stack(rasters1)
    fun(rasters1, ...)
  }
  
  rfm &lt;- fmerge(rasters1, mean, na.rm=T)
  </code></pre>
  <p>This is the error message:</p>
  <blockquote>
  <p>Error in raster(union(rasters1)) :
  error in evaluating the argument 'x' in selecting a method for function 'raster': Error in as.vector(y) : argument &quot;y&quot; is missing, with no default</p>
  </blockquote>