coerce function

Coercion to vector, matrix or array

Coercion to vector, matrix or array

Coercion of a SpatRaster to a vector, matrix or array. Or coerce a SpatExtent to a vector or matrix methods

## S4 method for signature 'SpatRaster' as.vector(x, mode='any') ## S4 method for signature 'SpatRaster' as.matrix(x, wide=FALSE, ...) ## S4 method for signature 'SpatRaster' as.array(x) ## S4 method for signature 'SpatRasterDataset' as.array(x) ## S4 method for signature 'SpatExtent' as.vector(x, mode='any') ## S4 method for signature 'SpatExtent' as.matrix(x, ...)

Arguments

  • x: SpatRaster or SpatVector
  • 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
  • ...: additional arguments (none implemented)

Returns

vector, matrix, or array

See Also

as.data.frame and as.polygons

Examples

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) as.vector(ext(r)) as.matrix(ext(r))
  • Maintainer: Robert J. Hijmans
  • License: GPL (>= 3)
  • Last published: 2025-02-26