raster (version 2.1-41)

as.matrix: Get a matrix with raster cell values

Description

as.matrix returns all values of a Raster* object as a matrix. For RasterLayers, rows and columns in the matrix represent rows and columns in the RasterLayer object. For other Raster* objects, the matrix returned by as.matrix has columns for each layer and rows for each cell. as.array returns an array of matrices that are like those returned by as.matrix for a RasterLayer If there is insufficient memory to load all values, you can use getValues or getValuesBlock to read chunks of the file.

Usage

as.matrix(x, ...)
as.array(x, ...)
as.vector(x, mode="any")

Arguments

x
Raster* or (for as.matrix and as.vector) Extent object
mode
character string giving an atomic mode or "list", or "any"
...
additional arguments: maxpixels Integer. To regularly subsample very large objects transpose Logical. Transpose the data? (for as.array only)

Value

  • matrix, array, or vector

Examples

Run this code
r <- raster(ncol=3, nrow=3)
r[] = 1:ncell(r)
as.matrix(r)
s <- stack(r,r)
as.array(s)
as.vector(extent(s))

Run the code above in your browser using DataCamp Workspace