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

reclassify

Reclassify


Description

Reclassify values of a Raster* object. The function (re)classifies groups of values to other values. For example, all values between 1 and 10 become 1, and all values between 11 and 15 become 2 (see functions subs and cut for alternative approaches).

Reclassification is done with matrix rcl, in the row order of the reclassify table. Thus, if there are overlapping ranges, the first time a number is within a range determines the reclassification value.

Usage

## S4 method for signature 'Raster'
reclassify(x, rcl, filename='', include.lowest=FALSE, right=TRUE, ...)

Arguments

x

Raster* object

rcl

matrix for reclassification. This matrix can have 3 or 2 columns.

In a 3-column matrix the first two columns are "from" - "to" for the input values, and the third column "becomes" has the new value for that range. (You can also supply a vector that can be coerced into a n*3 matrix (with byrow=TRUE)).

A 2-column matrix represents ("is", "becomes") which can be useful for integer values. In that case, the right argument is automatically set to NA

filename

character. Output filename (optional)

include.lowest

logical, indicating if a value equal to the lowest value in rcl (or highest value in the second column, for right = FALSE) should be included. The default is FALSE

right

logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa. The default is TRUE. A special case is to use right=NA. In this case both the left and right intervals are open

...

additional arguments as for writeRaster

Value

Raster* object

See Also

Examples

r <- raster(ncols=36, nrows=18)
values(r) <- runif(ncell(r)) 
# reclassify the values into three groups 
# all values > 0 and <= 0.25 become 1, etc.
m <- c(0, 0.25, 1,  0.25, 0.5, 2,  0.5, 1, 3)
rclmat <- matrix(m, ncol=3, byrow=TRUE)
rc <- reclassify(r, rclmat)

# for values >= 0 (instead of > 0), do
rc <- reclassify(r, rclmat, include.lowest=TRUE)

# equivalent to
rc <- reclassify(r, c(-Inf,0.25,1, 0.25,0.5,2, 0.5,Inf,3))

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

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