2

我正在尝试使用此代码,改编自数据集meuse

data<-list(var1,var2,x,y)

coordinates(data)=~x+y

grid = spsample(data, type = "regular", cellsize = c(0.05,0.05))

vt <- variogram(var1 ~ var2,data=data)

vt.fit <- fit.variogram(vt, vgm(0.2, "Sph", 800, 0.05))

gstatobj <- gstat(id = 'var1', formula = var1 ~ var2, model=vt.fit, set = list(gls=1))

我的目标是创建一个网格,例如meuse.grid. 但coordinates不起作用...... list 不是正确的命令。

我该用什么?我用来创建网格的方式是否正确?

4

1 回答 1

1

以下可重现的示例显示 jlhoward 的评论是正确的,而 Darko 的回复是错误的:

library(gstat)
var1 = 1:3; var2 = 1:3; x = 1:3; y = 1:3
data<-list(var1,var2,x,y)
coordinates(data) = ~x+y
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘coordinates<-’ for signature ‘"list"’
data<-data.frame(var1,var2,x,y)
coordinates(data) = ~x+y
class(data)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"

您可能会因为再次这样做而感到困惑,这将给出:

coordinates(data) = ~x+y
Error in `coordinates<-`(`*tmp*`, value = ~x + y) : 
  setting coordinates cannot be done on Spatial objects, where they have already been set

但保留现有的(和正确data的)机智。

于 2015-02-28T20:07:31.397 回答