subset_double | R Documentation |
Select a subset of layers from a SpatRaster or select a subset of records (row) and/or variables (columns) from a SpatVector.
## S4 method for signature 'SpatRaster,numeric,missing'
x[[i, j]]
## S4 method for signature 'SpatRasterDataset,ANY,ANY'
x[[i, j, drop=TRUE]]
## S4 method for signature 'SpatVector,numeric,missing'
x[[i, j, drop=FALSE]]
x |
SpatRaster or SpatVector |
i |
if if |
j |
missing, or, for SpatRasterDataset only, numeric |
drop |
logical. If |
if x
is a SpatRaster
or SpatRasterDataset
: SpatRaster
if x
is a SpatVector
: a data.frame
.
subset
, $
, [
, extract
### SpatRaster
s <- rast(system.file("ex/logo.tif", package="terra"))
s[[ 1:2 ]]
s[[c("red", "green")]]
# expression based (partial) matching of names with single brackets
s["re"]
s["^re"]
# does not with double brackets
# s[["re"]]
### SpatVector
v <- vect(system.file("ex/lux.shp", package="terra"))
v[[2:3]]
# to keep the geometry use
v[,2:3]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.