replace_layers: Replace layers or variables

replace_layersR Documentation

Replace layers or variables

Description

Replace the layers of SpatRaster with (layers from) another SpatRaster or replace variables of a SpatVector. You can also create new layers/variables with these methods.

Usage

## S4 replacement method for signature 'SpatRaster,numeric'
x[[i]] <- value

## S4 replacement method for signature 'SpatRaster,character'
x[[i]] <- value

## S4 replacement method for signature 'SpatVector,numeric'
x[[i]] <- value

## S4 replacement method for signature 'SpatVector,character'
x[[i]] <- value

Arguments

x

SpatRaster or SpatVector

i

if x is a SpatRaster: layer number(s) of name(s). If x is a SpatVector: variable number(s) or name(s) (column of the attributes)

value

if x is a SpatRaster: SpatRaster for which this TRUE: nlyr(value) == length(i). if x is a SpatVector: vector or data.frame

Value

SpatRaster

See Also

$<-, [<-

Examples

# raster
s <- rast(system.file("ex/logo.tif", package="terra"))   
s[["red"]] <- mean(s)
s[[2]] <- sqrt(s[[1]])

# vector
v <- vect(system.file("ex/lux.shp", package="terra"))
v[["ID_1"]] <- 12:1

rspatial/terra documentation built on Nov. 5, 2024, 5:13 p.m.