Description Usage Arguments Value Examples
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. You could also first use sampleRegular
The methods for Spatial* objects allow for easy creation of a data.frame with the coordinates and attributes; the default method only returns the attributes data.frame
1 2 3 4 5 6 7 8 9 10 11 | ## S4 method for signature 'Raster'
as.data.frame(x, row.names=NULL, optional=FALSE, xy=FALSE,
na.rm=FALSE, long=FALSE, ...)
## S4 method for signature 'SpatialPolygons'
as.data.frame(x, row.names=NULL, optional=FALSE,
xy=FALSE, centroids=TRUE, sepNA=FALSE, ...)
## S4 method for signature 'SpatialLines'
as.data.frame(x, row.names=NULL, optional=FALSE,
xy=FALSE, sepNA=FALSE, ...)
|
x |
Raster* object |
row.names |
|
optional |
logical. If |
xy |
logical. If |
na.rm |
logical. If |
long |
logical. If |
centroids |
logical. If |
sepNA |
logical. If |
... |
Additional arguments (none) |
data.frame
1 2 3 4 5 6 7 | r <- raster(ncol=3, nrow=3)
values(r) <- sqrt(1:ncell(r))
r[3:5] <- NA
as.data.frame(r)
s <- stack(r, r*2)
as.data.frame(s)
as.data.frame(s, na.rm=TRUE)
|
Loading required package: sp
layer
1 1.000000
2 1.414214
3 NA
4 NA
5 NA
6 2.449490
7 2.645751
8 2.828427
9 3.000000
layer.1 layer.2
1 1.000000 2.000000
2 1.414214 2.828427
3 NA NA
4 NA NA
5 NA NA
6 2.449490 4.898979
7 2.645751 5.291503
8 2.828427 5.656854
9 3.000000 6.000000
layer.1 layer.2
1 1.000000 2.000000
2 1.414214 2.828427
6 2.449490 4.898979
7 2.645751 5.291503
8 2.828427 5.656854
9 3.000000 6.000000
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.