Convert raster into matrix with R
问题 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: r <- raster(ncol=3, nrow=3) r[] <- 1:ncell(r) as.matrix(r) Here is what I got: Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : length of 'dimnames' [1] not equal to array extent I'm using RSTUDIO, R version 3.4.0 and