require(raster)
## Function to aggregate
fun.patch <- function(x) {
if (max(table(x)) >= 0.9 * length(x)) {
return(as.vector(which.max(table(x))))
}
else
return(NA)
}
r.lc <- raster(nrows = 100, ncols = 100)
r.lc[] <- 1:6
aggregate(r.lc, fact = c(5,5), fun.patch)
FUN中的错误(newX [,i],...):未使用的参数(na.rm = TRUE)
答案 0 :(得分:3)
来自?raster::aggregate
- 您传递的函数应接受或忽略na.rm
参数
要忽略,请在函数参数
中包含...
fun.patch <- function(x,...) {
if (max(table(x)) >= 0.9 * length(x)) {
return(as.vector(which.max(table(x))))
}
else
return(NA)
}
r.lc <- raster(nrows = 100, ncols = 100)
r.lc[] <- sample(1:6, 100^2, replace = T)
aggregate(r.lc, fact = c(5,5), fun.patch)