Learn R Programming

raster (version 1.9-13)

as.data.frame: Get a data.frame 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.data.frame(x, row.names=NULL, optional=FALSE, ...)

Arguments

x
Raster* object
row.names
NULL or a character vector giving the row names for the data frame. Missing values are not allowed.
optional
logical. If TRUE, setting row names and converting column names (to syntactic names: see make.names) is optional.
...
Additional arguments (none).

Value

  • data.frame

Examples

Run this code
r <- raster(ncol=3, nrow=3)
r[] = 1:ncell(r)
as.data.frame(r)
s <- stack(r,r)
as.data.frame(s)

Run the code above in your browser using DataLab