raster (version 1.1.7)

substitute: Substitute values in a RasterLayer

Description

Substitute (replace) values in a RasterLayer with values in a data.frame. The data.frame should have a column to identify the key (ID) to match with the values of the RasterLayer, and a column with the replacement values. By default these are the first and second column but you can specify other columns with arguments by and which (see under Methods).

Usage

subs(x, y, ...)

Arguments

x
A RasterLayer object
y
A data.frame
...
Additional arguments. See under Methods

Value

  • A new RasterLayer object, and in some cases, the side effect of a new file on disk.

Details

You could obtain the same result with reclass, but subs is more efficient for simple replacement. Use reclass if you want to replace ranges of values with new values. You can also replace values using a fitted model. E.g. fit a model to glm or loess and then call predict

See Also

reclass

Examples

Run this code
r <- raster(ncol=10, nrow=10)
r[] <- round(runif(ncell(r)) * 10)
df = data.frame(id=2:8, v=c(10,10,11,11,12:14))
x = subs(r, df)
x2 = subs(r, df, subsWithNA=FALSE)

Run the code above in your browser using DataLab