[GIS] Error in Kriging function

gstatkrigingr

I am using gstat::krige to interpolate a data set of arund 2700 points. However I get an error message "Error in seq.default(zrng[1], zrng[2], length.out = cuts + 2):'from' must be a finite number" and I don't understand what does it means.
My confusion is that when I do cross validation in the same data set, it works fine. When I do kriging interpolation in less than 2000 points sampled from the same data set, it works fine. But when I do kriging interpolation in the entire data set, predicted values (var1.pred) and variance (var1.var) results is NA.

I can't localized what throws the error. Below you can see what I did and in the link are my files:https://www.dropbox.com/sh/ff2231r2qobg4ud/AAB8aYHlObhakLKdySvLZFsSa?dl=0.
In the same link you will find the output of this.

library(sp)
library(gstat)
t1 <- read.table("SelecPts.iter.txt")
g1 <- read.table("Dh9709.grid.txt")
coordinates(t1) <- ~ x+y
coordinates(g1) <- ~ x+y
gridded(g1) <- T
Var <- variogram(dh9709~x+y, t1, alpha=c(45,135))
m <- fit.variogram(Var, vgm("Exp"))

Cross-validation works

cv1<-krige.cv(dh9709 ~ x+y, t1, model = m, verbose=T))

Kriging with 2700 point doesn't work

kg1<-krige(dh9709 ~ x+y, locations = t1, newdata = g1, model = m))

Best Answer

A common problem is when you have duplicate locations. When I tried to add the following line of code before creating a spatial object from t1:

...
t1 = t1[which(!duplicated(t1[1:2])), ]
coordinates(t1) <- ~ x+y
...

(which subsets rows from data frame t1 which have unique x and y values) the kriging process runs just fine and produces results. However, you should check yourself how to get rid of the duplicated locations and which rows to keep.