Learn R Programming

terra (version 1.7-55)

subset_double: Subset a SpatRaster or a SpatVector

Description

Select a subset of layers from a SpatRaster or select a subset of records (row) and/or variables (columns) from a SpatVector.

Usage

# S4 method for SpatRaster,numeric,missing
[[(x, i, j)

# S4 method for SpatRasterDataset,ANY,ANY [[(x, i, j, drop=TRUE)

# S4 method for SpatVector,numeric,missing [[(x, i, j, drop=FALSE)

Value

if x is a SpatRaster or SpatRasterDataset: SpatRaster

if x is a SpatVector: a data.frame.

Arguments

x

SpatRaster or SpatVector

i

if x is a SpatRaster: integer, logical, or character to select layers

if x is a SpatVector: integer, logical, or character to select variables

j

missing, or, for SpatRasterDataset only, numeric

drop

logical. If TRUE, the geometries will be dropped, and a data.frame is returned

See Also

subset, $, [, extract

Examples

Run this code
### 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]

Run the code above in your browser using DataLab