I have 2 raster stacks. I want to do some math between pairs of raster layers from each of the stacks, producing a 3rd raster stack of the same number of layers, ie;
r1<- raster stack 1 # 10 raster layers
r2<- raster stack 2 # 10 raster layers
r3<- sqrt(r1^2 + r2^2) # 10 raster layers
Is this the equivalent of the loop form (for illustrative purposes);
for (i in 1:10) {
r <- sqrt(r1[[i]]^2 + r2[[i]]^2)
r3 <-stack(r3,r)
}
Or is there a more efficient function or apply solution? Thanks.
r3 <- sqrt((r1 ** 2) + (r2 ** 2))
? – Mislav