subset_double: Subset a SpatRaster or a SpatVector

subset_doubleR Documentation

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 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]]

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

Value

if x is a SpatRaster or SpatRasterDataset: SpatRaster

if x is a SpatVector: a data.frame.

See Also

subset, $, [, extract

Examples

### 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]

terra documentation built on Oct. 14, 2024, 5:07 p.m.