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.

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))
  • Can you add a few lines on how to get from your data files to your R objects? When I try and fit the variogram I get a singular model warning and a model with an infinite psill....
    – Spacedman
    Jun 25, 2017 at 15:19
  • @Spacedman You mean de raw data. They are in shape file from arcgis using shapefiles package: Dh9709 <- data.frame(read.dbf("SelecPts.iter.dbf")) \n Dh9709.grid <- data.frame(read.dbf("grid.dbf")) \n coordinates(Dh9709) <- ~ x+y \n coordinates(Dh9709.grid) <- ~ x+y \n gridded(Dh9709.grid) <- T Jun 25, 2017 at 17:56
  • I edited your post to change your code to code blocks and add the data from your comment. However, the data you provided on Dropbox are not dbf files but, tab/space separated flat files. Please change your code to use the correct read function or just put up the original dbf files. If the original data are shapefiles just post them and use rdgal::readORG to read them. No need for read.dbf. I also added the required libraries, which you should have also indicated! Jun 25, 2017 at 19:27
  • @RubenBasantes what I meant was you've given us the .txt files, but not shown how to get your R objects form those text files. I tried using read.table and then converting to spatial objects (coordinates(thing)=~x+y) but couldn't replicate your problems.
    – Spacedman
    Jun 25, 2017 at 20:28
  • Sorry I am a newvi in the blog and also in R programming. @Jeffrey Evans I adjusted the code to work with txt files. Jun 26, 2017 at 16:27

1 Answer 1


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.

  • Thanks for your help. It was very useful, I improve the code and it run OK Jul 15, 2017 at 20:23
  • @RubenBasantes You can mark the answer as accepted if it solved your problem. Thanks :-)
    – Janina
    Jul 17, 2017 at 7:01
  • This can also happen if a lat/lon coordinate is within 1/10,000 of a decimal of another coordinate. So, if you're looking for coordinates that are "literally the same", you might miss some that are very close to each other, that are nonetheless considered duplicate. Jun 18, 2020 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.