Substitute (replace) values in a Raster* object with values in a data.frame. The data.frame should have a column to identify the key (ID) to match with the cell values of the Raster* object, and one or more columns with replacement values. By default these are the first and second column but you can specify other columns with arguments by and which. It is possible to match one table to multiple layers, or to use multiple layers as a single key, but not both.
methods
## S4 method for signature 'Raster,data.frame'subs(x, y, by=1, which=2, subsWithNA=TRUE, filename='',...)
Arguments
x: Raster* object
y: data.frame
by: column number(s) or name(s) identifying the key (ID) to match rows in data.frame y to values of the Raster object
which: column number or name that has the new (replacement) values
subsWithNA: logical. If TRUE values that are not matched become NA. If FALSE, they retain their original value (which could also be NA). This latter option is handy when you want to replace only one or a few values. It cannot be used when x has multiple layers
filename: character. Optional output filename
...: additional arguments as for writeRaster
Details
You could obtain the same result with reclassify, but subs is more efficient for simple replacement. Use reclassify 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