https://github.com/cran/gstat
Raw File
Tip revision: 36f1c257fa33bdf233c6a62e941c1c62288e4f5c authored by Edzer Pebesma on 08 January 2015, 14:02:52 UTC
version 1.0-20
Tip revision: 36f1c25
na.action.Rout.save

R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(sp)
> 
> data(meuse)
> data(meuse.grid)
> 
> set.seed(13131) # reproduce results
> 
> # select 10 random rows;
> # create two missing values in the coordinates:
> m = meuse.grid[sample(nrow(meuse.grid), 10), ]
> m[c(2,8), "x"] = NA
> 
> library(gstat)
> ## this is not allowed anymore:
> try(krige(log(zinc)~1,~x+y,meuse,m, na.action = na.pass))
Error in na.fail.default(structure(list(x = c(180300, NA, 179380, 179180,  : 
  missing values in object
> try(krige(log(zinc)~1,~x+y,meuse,m, na.action = na.omit))
Error in na.fail.default(structure(list(x = c(180300, NA, 179380, 179180,  : 
  missing values in object
> try(krige(log(zinc)~1,~x+y,meuse,m, na.action = na.exclude))
Error in na.fail.default(structure(list(x = c(180300, NA, 179380, 179180,  : 
  missing values in object
> try(krige(log(zinc)~1,~x+y,meuse,m, na.action = na.fail))
Error in na.fail.default(structure(list(x = c(180300, NA, 179380, 179180,  : 
  missing values in object
> 
> # select 10 random rows;
> # create two missing values in the regressor variable:
> m = meuse.grid[sample(nrow(meuse.grid), 10), ]
> m[c(3,7), "dist"] = NA
> krige(log(zinc)~dist,~x+y,meuse,m, na.action = na.pass)
[ordinary or weighted least squares prediction]
        x      y var1.pred  var1.var
1  180260 331740  5.110655 0.2425253
2  180420 331180  4.024709 0.2580362
3  178740 330740        NA        NA
4  178780 330180  5.815051 0.2392971
5  180900 333220  6.343871 0.2404070
6  179980 331580  5.272101 0.2413105
7  180740 332300        NA        NA
8  180660 330140  6.462357 0.2410713
9  179980 331700  5.345455 0.2408518
10 179540 329900  6.314501 0.2402659
> krige(log(zinc)~dist,~x+y,meuse,m, na.action = na.omit)
[ordinary or weighted least squares prediction]
          x      y var1.pred  var1.var
1121 180260 331740  5.110655 0.2425253
1613 180420 331180  4.024709 0.2580362
2684 178780 330180  5.815051 0.2392971
134  180900 333220  6.343871 0.2404070
1251 179980 331580  5.272101 0.2413105
2757 180660 330140  6.462357 0.2410713
1149 179980 331700  5.345455 0.2408518
2951 179540 329900  6.314501 0.2402659
> krige(log(zinc)~dist,~x+y,meuse,m, na.action = na.exclude)
[ordinary or weighted least squares prediction]
          x      y var1.pred  var1.var
1121 180260 331740  5.110655 0.2425253
1613 180420 331180  4.024709 0.2580362
2684 178780 330180  5.815051 0.2392971
134  180900 333220  6.343871 0.2404070
1251 179980 331580  5.272101 0.2413105
2757 180660 330140  6.462357 0.2410713
1149 179980 331700  5.345455 0.2408518
2951 179540 329900  6.314501 0.2402659
> try(krige(log(zinc)~dist,~x+y,meuse,m, na.action = na.fail))
Error in na.fail.default(structure(list(dist = c(0.527108, 0.929323, NA,  : 
  missing values in object
> 
> proc.time()
   user  system elapsed 
  1.027   0.040   1.053 
back to top