catalyze: Factors to numeric

Description Usage Arguments Value See Also Examples

Description

Change a categorical layer into one or more numerical layers. With as.numeric you can transfer the active category values to cell values in a non categorical SpatRaster. catalyze transfers all categories to new layers.

Usage

1
2
3
4
5
## S4 method for signature 'SpatRaster'
as.numeric(x, index=NULL, filename="", ...)

## S4 method for signature 'SpatRaster'
catalyze(x, filename="", ...)

Arguments

x

SpatRaster

index

positive integer, indicating the column in data.frame value to be used as the category, skipping the first column with the ID. If NULL the active category is used

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

See Also

activeCat, cats

Examples

1
2
3
4
5
6
7
8
9
set.seed(0)
r <- rast(nrows=10, ncols=10)
values(r) <- sample(3, ncell(r), replace=TRUE) + 10
d <- data.frame(id=11:13, cover=c("forest", "water", "urban"), letters=letters[1:3], value=10:12)
levels(r) <- d
catalyze(r)

activeCat(r) <- 3
as.numeric(r)

terra documentation built on Aug. 20, 2021, 9:07 a.m.