If have three rasters(as matrix):
r1 <- raster(nrows=10, ncols=10); r1 <- setValues(r1, 1:ncell(r1))
r16 <- raster(nrows=10, ncols=10);r16 <- setValues(r16, 1:ncell(r16))
r30 <- raster(nrows=10, ncols=10);r30 <- setValues(r30, 1:ncell(r30))
I would like to linearly interpolate r1,c16,c30
to find the values in between i.e. r2,r3,r4,......r15 then r17,r18,r19,..........r29
.
Is this possible using R?
Here is a way to do that
Here is another way to do it
But this will fail if there are NA values in the three layers. You would need to adjust the function
fun
to deal with that (here is an example).