【问题标题】:How to write a formula in a loop for autoKrige {automap} in R如何在 R 中的 autoKrige {automap} 循环中编写公式
【发布时间】:2017-09-06 03:10:25
【问题描述】:

我有一个大矩阵,列名如下:

colid=vector(length = 60)
for(i in 1"60) {
  colid[i]=paste0("V",i)
}

当我在automap中使用autoKrige函数时,公式必须写成这样的格式:V1~1。当我尝试使用循环执行此操作时,会发生错误:

library(automap)
value=list()
for(i in 1:60) {
  value[[i]]=autoKrige(colid[i]~1,Mydata,new_data = newgrid)
}

Error: too many spatial dimensions: 3068 In addition: Warning message:
NAs introduced by coercion 

然后我尝试解决这个问题,我测试公式:

> colid[10]~1
colid[10] ~ 1

所以,问题在于公式的格式不正确。我想知道我该如何解决这个问题?非常感谢。

【问题讨论】:

    标签: r formula spatial kriging


    【解决方案1】:

    使用函数as.formula将字符转换为公式:

    colid=vector(length = 60)
    value=list()
    for(i in 1:60) {
      colid[i] <- paste0("V",i, " ~ 1")
      value[[i]]=autoKrige(as.formula(colid[i]),Mydata,new_data = newgrid)
    }
    

    【讨论】:

    • 非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 2021-11-15
    • 2017-01-09
    相关资源
    最近更新 更多