2
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)

4

1 回答 1

5

From ?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)
于 2012-06-04T02:52:25.283 回答