subset_single | R Documentation |
Extract values from a SpatRaster; a subset of records (row) and/or variables (columns) from a SpatVector; or a number from a SpatExtent.
You can use indices (row, column, layer or cell numbers) to extract. You can also use other Spat* objects.
## S4 method for signature 'SpatRaster,ANY,ANY,ANY'
x[i, j, k]
## S4 method for signature 'SpatVector,numeric,numeric'
x[i, j, drop=FALSE]
## S4 method for signature 'SpatVector,SpatVector,missing'
x[i, j]
## S4 method for signature 'SpatExtent,numeric,missing'
x[i, j]
x |
SpatRaster, SpatVector or SpatExtent |
i |
if if if |
j |
numeric, logical, or missing to select columns |
k |
numeric, character, or missing to select layers |
drop |
logical. If |
numeric if x
is a SpatExtent.
Same as x
if drop=FALSE
. Otherwise a data.frame
extract
, subset
, $
, [[
### SpatRaster
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
r[3638]
rowColFromCell(r, 2638)
r[39, 28]
x <- r[39:40, 28:29, drop=FALSE]
as.matrix(x, wide=TRUE)
### SpatVector
v <- vect(system.file("ex/lux.shp", package="terra"))
v[2:3,]
v[1:2, 2:3]
v[1:2, 2:3, drop=TRUE]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.