Learn R Programming

tidyterra (version 1.3.0)

unite.Spat: Unite Spat* layers or attributes

Description

unite() combines multiple layers or attributes by pasting their values together.

Usage

# S3 method for SpatRaster
unite(data, col, ..., sep = "_", remove = TRUE, na.rm = FALSE)

# S3 method for SpatVector unite(data, col, ..., sep = "_", remove = TRUE, na.rm = FALSE)

Value

A SpatRaster or SpatVector object.

Arguments

data

A SpatRaster or SpatVector.

col

The name of the new column, as a string or symbol.

This argument is passed by expression and supports quasiquotation (you can unquote strings and symbols). The name is captured from the expression with rlang::ensym() (note that this kind of interface where symbols do not represent actual objects is now discouraged in the tidyverse; we support it here for backward compatibility).

...

<tidy-select> Columns to unite

sep

Separator to use between values.

remove

If TRUE, remove input columns from output data frame.

na.rm

If TRUE, missing values will be removed prior to uniting each value.

Methods

Implementation of the generic tidyr::unite() methods for Spat* objects.

SpatRaster

The selected layers are united cell by cell. The new layer is categorical because tidyr::unite() returns a character vector.

SpatVector

The geometry column has sticky behavior and is never united with attributes.

See Also

Examples

Run this code
library(tidyr)

v <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))

unite(v, "label", iso2, cpro, sep = "-")

r <- terra::rast(system.file("extdata/cyl_temp.tif", package = "tidyterra"))

unite(r, "label", tavg_04, tavg_05, sep = "-", remove = FALSE)

Run the code above in your browser using DataLab