我正在使用包中的一个非常基本的聚合aggregate
操作terra
。主要思想是使用以下函数计算具有值的像素占整数的百分比:
nofun = function(x){ length(na.omit(x))/length(x) * 100 }
不幸的是,aggregate
在不同的条件下失败 - 甚至更简单 - 我无法弄清楚我做错了什么。
第一次尝试:aggregate(chm, fact=20, fun=length, na.rm=T) # w/o na.rm=T
Error in FUN(X[[i]], ...) : 2 arguments passed to 'length' which requires 1
第二次尝试:
aggregate(chm, fact=20, fun=function(x){ length(x) } )
Error: [aggregate] this function does not return the correct number of values
应用上述根据本回复修改的最终函数的结果相同,如下:
function(x){ if(any(is.numeric(x))){length(na.omit(x))/length(x) * 100} else {NA_real_}}
terra
1.4.22
在 W10 中和1.5.12
在 W10 上进行的所有测试。