Learn R Programming

terra (version 1.5-34)

coerce: Coercion of a SpatRaster to a vector, matrix or array

Description

Coercion to other object types

Usage

# S4 method for SpatRaster
as.vector(x, mode='any')

# S4 method for SpatRaster as.matrix(x, ...)

# S4 method for SpatRaster as.array(x)

Arguments

x

SpatRaster or SpatVector

...

additional argument as.matrix: wide (logical). If FALSE each layer in the SpatRaster becomes a column in the matrix and each cell in the SpatRaster becomes a row. If TRUE each row in the SpatRaster becomes a row in the matrix and each column in the SpatRaster becomes a column in the matrix

mode

this argument is ignored

Value

vector, matrix, or array

See Also

as.data.frame and as.polygons

Examples

Run this code
# NOT RUN {
r <- rast(ncols=2, nrows=2)
values(r) <- 1:ncell(r)

as.vector(r)
as.matrix(r)
as.matrix(r, wide=TRUE)
as.data.frame(r, xy=TRUE)
as.array(r)

# }

Run the code above in your browser using DataLab