gpt4 book ai didi

raster::aggregate() 函数不适用于我自己的函数

转载 作者:行者123 更新时间:2023-12-02 22:40:17 24 4
gpt4 key购买 nike

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)

最佳答案

来自 ?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)

关于raster::aggregate() 函数不适用于我自己的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10875546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com