I'm trying to create a new, smaller NDVI raster with the upper quantile of raster values for the new aggregated cells.
library(raster)
rast <- raster("ndvi.tif")
Now I'd like to create the new raster downsampled by a factor of 10, using a quantile function for the top 25% of the data:
rast2 <- aggregate(x = rast, fact = 10,
fun = function(i) quantile(i, probs = 0.75, na.rm = T))
This always gives an error:
Error in FUN(newX[, i], ...) : unused argument (na.rm = TRUE)
Called from: FUN(newX[, i], ...)
If I use mean
or max
it works just fine, only quantile
gives an error. I've also tried defining a custom function but with the same result.
Best Answer
aggregate
is passing anna.rm
function to yourfun
function:But
fun
is onlyfunction(i)
so it fails. You can fix this either by:to ignore any
na.rm
values, or possibly:which will pass through any
na.rm
value passed toaggregate
.This is documented in the help for
raster::aggregate
: