Skip to content

Antw: arithmetic with layers from a raster stack/brick

1 message · Oscar Perpiñan

#
Hi,

Another solution:

r <- raster(nrows=2, ncols=2)
r[] <- 1:ncell(r)
s <- stack(r, r, r, r)
names(s) <- letters[1:4]

## all the layers
sum(s)
## only a subset
sum(subset(s, c('a', 'b')))

Best,

Oscar.

Etienne B. Racine <etiennebr at gmail.com> writes: