r1 <- raster(ncols=10, nrows=10)
values(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)
# recycling by row
r4 <- r1 * 0 + 1:ncol(r1)
# multi-layer object mutiplication, no recycling
b1 <- brick(r1, r2, r3)
b2 <- b1 * 10
# recycling by layer
b3 <- b1 + c(1, 5, 10)
# addition of the cell-values of two RasterBrick objects
b3 <- b2 + b1
# summing two RasterBricks and one RasterLayer. The RasterLayer is 'recycled'
b3 <- b1 + b2 + r1
Run the code above in your browser using DataLab