简体   繁体   English

逆距离加权:spDists(s0, s) 中的错误:ncol(x) == ncol(y) 在 package gstat 中不是 TRUE

[英]Inverse Distance Weighting : Error in spDists(s0, s) : ncol(x) == ncol(y) is not TRUE in package gstat

I wish to do some "simple" inverse distance weighing.我希望做一些“简单”的反距离称重。 In the past I have used the idw function in gstat but that stopped working.过去我在 gstat 中使用过 idw function 但它停止工作。 I found an equivalent idw0 in the same package but I can not get that to work.我在同一个 package 中找到了一个等效的 idw0,但我无法让它工作。 This example code should produce 50 estimates for z-hat at the 50 points in the unknown.df data frame.此示例代码应在 unknown.df 数据帧的 50 个点处生成 50 个 z-hat 估计值。

library(gstat)

set.seed(1)
x<-runif(100,0,1)
y<-runif(100,0,1)
z<-runif(100,0,1)
known.df<-data.frame(x,y,z)

x<-runif(50,0,1)
y<-runif(50,0,1)
unknown.df<-data.frame(x,y)

idw<-idw0(z~1,known.df,unknown.df)
idw<-idw0(z~1,known.df,unknown.df,y=as.matrix(known.df$z))

This produces the errors这会产生错误

> idw<-idw0(z~1,known.df,unknown.df)
Error in spDists(s0, s) : ncol(x) == ncol(y) is not TRUE
> idw<-idw0(z~1,known.df,unknown.df,y=as.matrix(known.df$z))
Error in spDists(s0, s) : ncol(x) == ncol(y) is not TRUE

Y has length 50, but what is x? Y 的长度为 50,但 x 是什么?

Need to explicitly denote the coordinate fields.需要明确表示坐标字段。

library(gstat)
library(sp)

set.seed(1)
x<-runif(100,0,1)
y<-runif(100,0,1)
z<-runif(100,0,1)
known.df<-data.frame(x,y,z)
coordinates(known.df) = ~ x + y

x<-runif(50,0,1)
y<-runif(50,0,1)
unknown.df<-data.frame(x,y)
coordinates(unknown.df) = ~ x + y

idw<-idw0(z~1,known.df,unknown.df)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (p &lt;-ncol(X))== ncol(Y)在glmer中不是TRUE错误 - (p <- ncol(X)) == ncol(Y) is not TRUE error in glmer 混合效应中的错误 Model 代码:“(p <- ncol(X)) == ncol(Y) 不是 TRUE”和“可变长度不同” - Errors in Mixed Effects Model Code: "(p <- ncol(X)) == ncol(Y) is not TRUE" and "variable lengths differ" 在plyr包的each()函数中解释ncol结果 - interpreting ncol result in plyr package's each() function tidytext 错误(is_corpus_df(corpus) 中的错误:ncol(corpus) &gt;= 2 is not TRUE) - tidytext error (Error in is_corpus_df(corpus) : ncol(corpus) >= 2 is not TRUE) xts时间序列与if(ncol(x)== 1){中的参数的长度为零的误差之间的关系 - Relation of xts Time Series and Error in if (ncol(x) == 1) { : argument is of length zero 尝试相关分析时出现错误:“ 1:ncol(y)中的错误:长度为0的参数” - Error: “Error in 1:ncol(y) : argument of length 0” when attempting correlation analysis 诊断错误:当 x 是矩阵时,不能指定 nrow 或 ncol - diag error: nrow or ncol cannot be specified when x is a matrix “1中的错误:ncol(x):长度为0的参数”在R中使用Amelia时 - “Error in 1:ncol(x) : argument of length 0” when using Amelia in R 拼凑“ncol”错误:主题元素“ncol”未在元素层次结构中定义 - patchwork 'ncol' Error: Theme element `ncol` is not defined in the element hierarchy 在R的gstat包中创建变异函数 - Create variogram in R's gstat package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM