Filter R中的错误:“0”;“无适用方法”;用于光栅中的focal()函数

Filter R中的错误:“0”;“无适用方法”;用于光栅中的focal()函数,filter,landscape,r-raster,entropy,Filter,Landscape,R Raster,Entropy,我想应用一个移动窗口(3x3)来估计异质景观上的条件熵(Nowosad&Stepinsky,2019): entropy=function(r){ entropy=lsm_l_condent(r, neighbourhood = 4, ordered = TRUE, base = "log2") return(entropy$value) } w=matrix(1,3,3) result=focal(r, w, fun=entropy) 但是,我得到了这个错误: E

我想应用一个移动窗口(3x3)来估计异质景观上的条件熵(Nowosad&Stepinsky,2019):

entropy=function(r){
  entropy=lsm_l_condent(r, neighbourhood = 4, ordered = TRUE, base = "log2")
  return(entropy$value)
}
w=matrix(1,3,3)
result=focal(r, w, fun=entropy)
但是,我得到了这个错误:

Error in .focal_fun(values(x), w, as.integer(dim(out)), runfun, NAonly) : 
Evaluation error: no applicable method for 'lsm_l_condent' applied to an object of class "c('double', 'numeric')".
但是,当我在整个景观中运行熵函数时,它是有效的:

> entropy(r)
[1] 2.178874
r是一个INT4U光栅对象:

class      : RasterLayer
dimensions : 886, 999, 885114  (nrow, ncol, ncell)
resolution : 300, 300  (x, y)
extent     : 934805.7, 1234506, 1006566, 1272366  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=4.59620041666667 +lon_0=-74.0775079166667 +k=1 +x_0=1000000 +y_0=1000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
values     : 99, 321113  (min, max)
有没有办法解决“无适用方法”的错误?或者用移动窗口来估计条件熵

提前谢谢你的帮助

最好的

詹姆