I'm trying to resample/project a high res raster, using a low res raster as a template
library("terra")
high_res <- rast(ncol = 2, nrow = 2, vals = c(1, NA, NA, NA))
low_res <- rast(nrow = 1, ncol = 1)
new_rast <- project(high_res, low_res, method = "average")
This works fine, but the value in the cell of the new rast is '1' as it has taken the average of all non-NA cells from the high_res raster.
Instead, I want it to treat NA values as 0. The result should be 0.25, not 1.
The method to do this must be memory-safe as I will be doing this on very large rasters (think 5m resolution covering a whole country).
Is there a clever way of doing this please?
You can simply replace
NAvalues with0s