当响应变量或预测变量包含缺失值 ( ) 时,函数和包中的函数会不断报告错误,idw()
即使设置为:krige()
gstat
NA
na.action
na.omit
require(gstat)
data(meuse)
coordinates(meuse) = ~x+y
data(meuse.grid)
gridded(meuse.grid) = ~x+y
meuse2 <- as.data.frame(meuse)
meuse2[1, 'zinc'] <- NA
meuse2 <- SpatialPointsDataFrame(SpatialPoints(meuse), meuse2)
# idw response var
int <- idw(zinc ~ 1, meuse2, meuse.grid, na.action = na.omit)
# Error: dimensions do not match: locations 310 and data 154
# krige response var
m <- vgm(.59, "Sph", 874, .04)
int <- krige(zinc ~ 1, meuse2, meuse.grid, model = m, na.action = na.omit)
# Error: dimensions do not match: locations 310 and data 154
# krige predictor var
meuse3 <- as.data.frame(meuse)
meuse3[1, 'dist'] <- NA
meuse3 <- SpatialPointsDataFrame(SpatialPoints(meuse), meuse3)
int <- krige(zinc ~ dist, meuse3, meuse.grid, model = m, na.action = na.omit)
# Error: dimensions do not match: locations 310 and data 154
这是一个错误吗?我们真的必须手动过滤数据并将结果合并回原始数据框吗?没有更简单的解决方案吗?那为什么还有这个na.action
选项?