【发布时间】:2021-12-18 17:05:23
【问题描述】:
我正在尝试使用反距离加权来插入一些值,但我收到了这个 unhelfull 错误消息:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘idw’ for signature ‘"missing", "SpatialPointsDataFrame"’
我的数据基于英国国家电网,此代码段复制了该问题:
library(gstat)
library(sp)
set.seed(1)
x <- sample(30000, 1000) + 400000
y <- sample(30000, 1000) + 410000
z <- runif(1000)
source.spdf <- data.frame(x, y, z)
coordinates(source.spdf) <- ~x+y
x <- sample(30000, 100) + 400000
y <- sample(30000, 100) + 410000
destination.spdf <- data.frame(x, y)
coordinates(destination.spdf)<- ~x+y
idw.fit<-idw(formual=z~1, locations=source.spdf, newdata=destination.spdf, idp=2.0)
谁能帮助更好地解释错误信息?谢谢。
【问题讨论】:
-
我认为这只是一个错字。如果您将
formual=z~1更改为formula=z~1,那么它似乎可以按预期工作。错误消息是因为formula“丢失” -
@AllanCameron 可能值得将其作为答案,因为错误消息似乎不在网络上的其他地方,因此它可能对其他人有用
-
作为
debugonce(idw)的细心读者值得一试,在 gstat 中展示了广泛的类型和错误覆盖范围,但最终不会告诉您您输入了错误的“formual”。 -
Stephen - 我已经尝试用一个最小的可重现示例来解释错误是如何产生的
-
@stevec 我没有意识到它是如此晦涩难懂。我已经写了一个解释它是如何产生的。谢谢
标签: r interpolation spatial