categorize: Categorizing continious data

categorizeR Documentation

Categorizing continious data

Description

A function to categorize (discretize or binning) numerical data in the form of a raster layer, or a vector.

Usage

categorize(x,nc,probs,...)

Arguments

x

A SpatRaster or RasterLayer or a numerical vector

nc

A single numeric: Number of classes, or a vector specifying the categorization thresholds (in case if x is a multi-layer raster, nc can be a list of vectors); if missing, it will be automatically detected

probs

a two-item numeric vector of the lower and upper probabilities within the range of [0,1], e.g., c(0.025, 0.975) (default: NULL) to consider a quantile range of values in categorization (to avoid the effects of outliers); if NULL or FALSE, then the whole range is used.

...

Additional parameters for writeRaster function (filename should be specified as additional argument)

Details

If nc is not specified, the function calls the function nclass to find the best number of classes. For the details of how nclass works, see the reference.

When outliers do exist in x, it is likely that they affect the quality of categorization. To avoid their affects, a quantile with the specified probabilities can be used. default is recommended: c(0.025,0.975), but to ignore it, you can turn the probs argument to NULL.

Value

RasterLayer

if x is a RasterLayer

numeric vector

if x is a numeric vector

Author(s)

Babak Naimi naimi.b@gmail.com

http://r-gis.net

References

Naimi, B., Hamm, N. A., Groen, T. A., Skidmore, A. K., Toxopeus, A. G., & Alibakhshi, S. (2019). ELSA: Entropy-based local indicator of spatial association. Spatial statistics, 29, 66-88.

Examples


categorize(1:10,3) # categorizeing a numeric vector into 3 categories

file <- system.file('external/dem_example.grd',package='elsa')
r <- raster(file)
plot(r,main='a continuous raster map')
rc <- categorize(r,nc=4)
plot(rc, main='categorized map')


babaknaimi/elsa documentation built on Jan. 28, 2024, 10 a.m.