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).subs(x, y, ...)
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 predictreclass
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