Arithmic with rasters
Standard arithmic operators for computations with RasterLayer objects and numeric values. The following operators are available:
+, -, *, /, ^, %%, %/%
Operators are applied on a cell by cell basis, and single numeric values are recycled.
Input RasterLayers must have the same extent and resolution.
If the values of the output RasterLayer cannot be held in memory, they will be saved to a temporary file unless a default filename has been set with
rasterOptions. You can also use
rasterOptions to set the format, datatype and overwrite options.
- A RasterLayer object, and in some cases the side effect of a new file on disk.
r1 <- raster(ncols=10, nrows=10) r1 <- runif(ncell(r1)) r2 <- setValues(r1, 1:ncell(r1) / ncell(r1) ) r3 <- r1 + r2 r2 <- r1 / 10 r3 <- r1 * (r2 - 1 + r1^2 / r2)