I would like to use the function aggregate (R raster package) to assign to a grid point of the new raster the number of grid points of the old raster that have a certain value
for(val in 1:10)
{
new.raster <- aggregate(old.raster, 10, fun = function(x) length(x[x == val], na.rm=TRUE))
#...some computation involving new.raster...
}
I've moved "na.rm = TRUE" around in every way imaginable, but R keeps complaining about an "Error in FUN(newX[, i], ...) : unused argument (na.rm = TRUE)". Any ideas?
If it's possible to write this piece of code in a more efficient manner (having the function fun outside the aggregate function, or the like), I'd be happy if you could let me know as well, as I'm running the code for a very large number of rasters.