coerce.Rd
Coercion to other object types
# S4 method for SpatRaster
as.vector(x, mode='any')
# S4 method for SpatRaster
as.matrix(x, wide=FALSE, ...)
# S4 method for SpatRaster
as.array(x)
SpatRaster or SpatVector
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
this argument is ignored
additional arguments (none implemented)
vector, matrix, or array
r <- rast(ncols=2, nrows=2)
values(r) <- 1:ncell(r)
as.vector(r)
#> [1] 1 2 3 4
as.matrix(r)
#> lyr.1
#> [1,] 1
#> [2,] 2
#> [3,] 3
#> [4,] 4
as.matrix(r, wide=TRUE)
#> [,1] [,2]
#> [1,] 1 2
#> [2,] 3 4
as.data.frame(r, xy=TRUE)
#> x y lyr.1
#> 1 -90 45 1
#> 2 90 45 2
#> 3 -90 -45 3
#> 4 90 -45 4
as.array(r)
#> , , 1
#>
#> [,1] [,2]
#> [1,] 1 2
#> [2,] 3 4
#>