I have several cropped rasters with different geometry/outlines. Specifically spatial yield maps from several years of the same field, but the extent varies - the measurements were not always overall the whole field, but in some years only part of it. I want to calculate a mean value of those maps and combine them into one mean-value-raster. That does mean however, that not for every pixel in let's say 5 layers/rasters there is a value. I could accept these missing values to be NA, so the final mean value would only be calculated by let's say 3 rasters for parts of the field, where the maps are not overlapping.
I thought of extending the raster with 'extend{raster}', filling the non-overlapping parts with NA values:
y <- extend(y, shape, value=NA)
#Shape is a rectangular shape that enframes all yield map rasters
That works fine, for all rasters. But they still don't have the same extent. Even if I adjust the extent by setExtent()
or extent() <- extent()
to the extent of the rectangular shapefile or even to one of the other extended rasters, I still get:
Error in compareRaster(x) : different number or columns
..when I want to stack them and use calc(y, fun=mean,...)
. The original raster extents are too different to resample. But they do have the same resolution and CRS.
Has anyone an idea how to solve this?