Reputation: 143
Assume that I have large RasterBrick, and I would like to do consecutive difference, which means layer2-layer1, layer3-layer2, layer4-layer3, ……..
I was thinking to use Raster package for this, but i am not able to do it. Could any one suggest me a working (guessing) code please ? I am not providing reproducible data thinking that the issue is clear. Thanks in advance.
Upvotes: 1
Views: 171
Reputation: 4121
The following seems to work:
library(raster)
r1 = raster()
r2 = raster()
r3 = raster()
dim(r2)
r1[] = runif(180*360)
r2[] = runif(180*360)
r3[] = runif(180*360)
r = stack(r1,r2,r3)
dim(r)
rd = calc(r, fun = diff)
dim(rd)
Upvotes: 8