Skip to content

Antw: arithmetic with layers from a raster stack/brick

2 messages · Matteo Mattiuzzi, Etienne B. Racine

#
Dear Ani,


Your "a" and "b" are not objects, they are the name the layers in your object "s". So you can't treat it that way.


Maybe this is what you want?


require(raster)
r<- raster(nrows=2, ncols=2)
r[]<-1:ncell(r)
s<-stack(r,r)
names(s)<-c("a","b")



r1<- s[["a"]] + s[["b"]]


Matteo
Dear List,

I'm trying to perform some arithmetic operation with layers of a raster
object. What I'm trying is
# now I want to add the layers of the raster "r" using their corresponding
names,i.e. "a" and "b" so that I get
I don't want to use subset (or any other methods) to define "a" or "b".
This may be very trivial, but I couldn't do it.

Any suggestions?

Thanks