r - idw() or krige() Error: dimensions do not match when missing values -


functions idw() , krige() gstat package keep reporting errors when either response or predictor variable contains missing values (na), when na.action set 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 not match: locations 310 , 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 not match: locations 310 , 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 not match: locations 310 , data 154 

is bug? have filter our data manually , merge results original data frames? isn't there easier solution? why there na.action option then?

the na.action argument deals missing values within newdata (not locations or data).

this stated in ?idw / ?krige / ?predict.gstat

function determining should done missing values in 'newdata'. default predict 'na'. missing values in coordinates , predictors both dealt with.

there no method deal na values within locations or data (and hence error saying there 2 more values in locations data (ie. x , y coordinate of missing data point)

you can work removing location missing value

int <- idw(zinc ~ 1, meuse2[!is.na(meuse2$zinc),],newdata= meuse.grid) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -