[R-sig-Geo] DataGrid

Sarah Goslee sarah.goslee at gmail.com
Sun Oct 15 13:12:39 CEST 2017


When you create a full grid, there will be many NA values in your data for
grid coordinates that you didn't provide data for.

str() is only showing you the first few elements: unless your dataset has
values in that corner, NA is the expected return.

Use summary() or image() to investigate the whole dataset. I think you will
find that you have non-missing values where appropriate. You need to then
use na.rm=TRUE in many functions.

Sarah

On Sun, Oct 15, 2017 at 5:39 AM Anastasia Johannes <stacy.johannes at gmail.com>
wrote:

> I am trying to create DataGrid but I am failing to do so
>
> Below find my code and see how my grid dataset just end up with no data.
>
> > library(sp)
>
> > library(gstat)
>
> > coordinates(cor)=~x+y
>
> > str(cor)
>
> Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
>
>   ..@ data       :'data.frame': 550 obs. of  28 variables:
>
>   .. ..$ F         : num [1:550] 22.2 65 44.4 30 88.2 ...
>
>   .. ..$ Poor        : num [1:550] 0 85 0 65 35.3 ...
>
>   .. ..$ Middle      : num [1:550] 0 15 0 30 58.8 ...
>
>   .. ..$ NoEdu       : num [1:550] 0 35 0 5 17.6 ...
>
>   .. ..$ Prim        : num [1:550] 0 25 5.56 65 47.06 ..
>
>
>
> > gridded(cor)<-TRUE
>
> > str(cor)
>
> Formal class 'SpatialPixelsDataFrame' [package "sp"] with 7 slots
>
>   ..@ data       :'data.frame': 550 obs. of  28 variables:
>
>   .. ..$ F         : num [1:550] 22.2 65 44.4 30 88.2 ...
>
>   .. ..$ Poor        : num [1:550] 0 85 0 65 35.3 ...
>
>   .. ..$ Middle      : num [1:550] 0 15 0 30 58.8 ...
>
>   .. ..$ NoEdu       : num [1:550] 0 35 0 5 17.6 ...
>
>   .. ..$ Prim        : num [1:550] 0 25 5.56 65 47.06 ...
>
>   .. ..$ Sec         : num [1:550] 88.9 40 22.2 25 35.3 ...
>
>
>
> *But when I transform to spatialGrid, the data disappear and this cause NA
> in the calculation of var1.pred and var.var*
>
> > fullgrid(cor)<-TRUE
>
> > str(cor)
>
> Formal class 'SpatialGridDataFrame' [package "sp"] with 4 slots
>
>   ..@ data       :'data.frame': 1372406 obs. of  28 variables:
>
>   .. ..$ HH         : num [1:1372406] NA NA NA NA NA NA NA NA NA NA ...
>
>   .. ..$ Poor        : num [1:1372406] NA NA NA NA NA NA NA NA NA NA ...
>
>   .. ..$ Middle      : num [1:1372406] NA NA NA NA NA NA NA NA NA NA ...
>
>   .. ..$ NoEdu       : num [1:1372406] NA NA NA NA NA NA NA NA NA NA ...
>
>   .. ..$ Prim        : num [1:1372406] NA NA NA NA NA NA NA NA NA NA ...
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list