Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

segregate

segregate


Description

Create a SpatRaster with a layer for each class (value, or subset of the values) in the input SpatRaster. For example, if the input has vegetation types, this function will create a layer (presence/absence; dummy variable) for each of these classes. Classes and cell values are always truncated to integers.

This is called "one-hot encoding" or "dummy encoding" (for a dummy encoding scheme you can remove (any) one of the output layers as it is redundant).

Usage

## S4 method for signature 'SpatRaster'
segregate(x, classes=NULL, keep=FALSE, other=0, filename="", ...)

Arguments

x

SpatRaster

classes

numeric. The values (classes) for which layers should be made. If NULL all classes are used

keep

logical. If TRUE, cells that are of the class represented by a layer get that value, rather than a value of 1

other

numeric. Value to assign to cells that are not of the class represented by a layer

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

Examples

r <- rast(nrow=5, ncol=5)
values(r) <- rep(c(1:4, NA), each=5)
b <- segregate(r)
bb <- segregate(r, keep=TRUE, other=NA)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.