| select.Spat {tidyterra} | R Documentation |
Subset layers/attributes of Spat* objects
Description
Select (and optionally rename) attributes/layers in Spat* objects, using a
concise mini-language. See Methods.
Usage
## S3 method for class 'SpatRaster'
select(.data, ...)
## S3 method for class 'SpatVector'
select(.data, ...)
Arguments
.data |
A |
... |
< |
Value
A Spat* object of the same class than .data. See Methods.
terra equivalent
Methods
Implementation of the generic dplyr::select() function.
SpatRaster
Select (and rename) layers of a SpatRaster. The result is a SpatRaster
with the same extent, resolution and crs than .data. Only the number (and
possibly the name) of layers is modified.
SpatVector
The result is a SpatVector with the selected (and possibly renamed)
attributes on the function call.
See Also
dplyr::select(), terra::subset()
Other single table verbs:
arrange.SpatVector(),
filter.Spat,
mutate.Spat,
rename.Spat,
slice.Spat,
summarise.SpatVector()
Other dplyr verbs that operate on columns:
glimpse.Spat,
mutate.Spat,
pull.Spat,
relocate.Spat,
rename.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,
mutate.Spat,
pull.Spat,
relocate.Spat,
rename.Spat,
rowwise.SpatVector(),
slice.Spat,
summarise.SpatVector()
Examples
library(terra)
# SpatRaster method
spatrast <- rast(
crs = "EPSG:3857",
nrows = 10,
ncols = 10,
extent = c(100, 200, 100, 200),
nlyr = 6,
vals = seq_len(10 * 10 * 6)
)
spatrast %>% select(1)
# By name
spatrast %>% select(lyr.1:lyr.4)
# Rename
spatrast %>% select(a = lyr.1, c = lyr.6)
# SpatVector method
f <- system.file("extdata/cyl.gpkg", package = "tidyterra")
v <- vect(f)
v
v %>% select(1, 3)
v %>% select(iso2, name2 = cpro)