| mutate.Spat | R Documentation |
Spat* objectsmutate() adds new layers/attributes and preserves existing ones on a
Spat* object.
## S3 method for class 'SpatRaster'
mutate(
.data,
...,
.keep = c("all", "used", "unused", "none"),
.before = NULL,
.after = NULL
)
## S3 method for class 'SpatVector'
mutate(
.data,
...,
.by = NULL,
.keep = c("all", "used", "unused", "none"),
.before = NULL,
.after = NULL
)
.data |
A |
... |
< The value can be:
|
.keep |
Control which columns from
|
.before, .after |
< |
.by |
< |
A Spat* object of the same class than .data. See Methods.
Some terra methods for modifying cell values:
terra::ifel(), terra::classify(), terra::clamp(), terra::app(),
terra::lapp(), terra::tapp()
Implementation of the generic dplyr::mutate() method.
SpatRasterAdd new layers and preserves existing ones. The result is a
SpatRaster with the same extent, resolution and CRS than .data. Only the
values (and possibly the number) of layers is modified.
SpatVectorThe result is a SpatVector with the modified (and possibly renamed)
attributes on the function call.
dplyr::mutate() methods.
terra provides several ways to modify Spat* objects:
terra::ifel().
terra::classify().
terra::clamp().
terra::app(), terra::lapp(), terra::tapp().
Other single table verbs:
arrange.SpatVector(),
filter.Spat,
rename.Spat,
select.Spat,
slice.Spat,
summarise.SpatVector()
Other dplyr verbs that operate on columns:
glimpse.Spat,
pull.Spat,
relocate.Spat,
rename.Spat,
select.Spat
Other dplyr methods:
arrange.SpatVector(),
bind_cols.SpatVector,
bind_rows.SpatVector,
count.SpatVector(),
distinct.SpatVector(),
filter-joins.SpatVector,
filter.Spat,
glimpse.Spat,
group-by.SpatVector,
mutate-joins.SpatVector,
pull.Spat,
relocate.Spat,
rename.Spat,
rowwise.SpatVector(),
select.Spat,
slice.Spat,
summarise.SpatVector()
library(terra)
# SpatRaster method
f <- system.file("extdata/cyl_temp.tif", package = "tidyterra")
spatrast <- rast(f)
mod <- spatrast |>
mutate(exp_lyr1 = exp(tavg_04 / 10)) |>
select(tavg_04, exp_lyr1)
mod
plot(mod)
# SpatVector method
f <- system.file("extdata/cyl.gpkg", package = "tidyterra")
v <- vect(f)
v |>
mutate(cpro2 = paste0(cpro, "-CyL")) |>
select(cpro, cpro2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.