title: Convert raster into matrix with R
body: <p>I'm currently convert original matrix into a raster to use the focal function, then I would like to convert back the raster into matrix. But I have an error message when I try to use the raster function as.matrix().
  Even with this very simple example:</p>
  <pre><code>r &lt;- raster(ncol=3, nrow=3)
  r[] &lt;- 1:ncell(r)
  as.matrix(r)
  </code></pre>
  <p>Here is what I got:</p>
  <blockquote>
  <p>Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  :</p>
  <p>length of 'dimnames' [1] not equal to array extent</p>
  </blockquote>
  <p>I'm using RSTUDIO, R version 3.4.0 and <code>ncdf4</code>, <code>raster</code> and <code>rgdal</code> librairies.</p>
  <p>Thank you for your help.</p>