I'm struggling with a function from the inlabru R package, which could help me fill in the NAs in my data.
According to the helpfile, I need:
bru_fill_missing(
data,
where,
values)
data
is a SpatialPointsDataFrame
, which I have - it contains a data.frame
of 17 climate variables, some of these include NAs.
where
should be "A matrix, data.frame
, or SpatialPoints
or SpatialPointsDataFrame
, containing the locations of the evaluated values" - I'm guessing this would be the coordinates of the SpatialPointsDataFrame
?
values
is "A vector of values to be filled in where is.na(values)
is TRUE
" - so this should be one of the climate variables from the SpatialPointsDataFrame
.
cec2 <- inlabru:::bru_fill_missing(grid2, grid2@coords, grid2$cec)
...gives me:
Error in inlabru:::bru_fill_missing(grid2, grid2@coords, grid2$cec) :
inherits(data, c("SpatialPixelsDataFrame", "SpatialGridDataFrame")) is not TRUE
Why is this not working? I seem to be using the right sort of objects:
> class(grid2@coords)
[1] "matrix" "array"
> class(grid2)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
> class(grid2$cec)
[1] "numeric"
> grid2
class : SpatialPointsDataFrame
features : 12179
extent : 499974.9, 1928094, 8696615, 9781413 (xmin, xmax, ymin, ymax)
crs : NA
variables : 17
names : gbifID, Species, ID, Latitude, Longitude, costpath, cec, Temp10, thermicity, tri, fpar, lai, Elev, soc_0.5cm, sq3, ...
min values : 49, Abelmoschus manihot, 1, -11.521, 141, 0.158908026, 4.099550837, 0, 12.01840072, 0.160710489, 5.959515748, 1.23322692, 0, 43.46748724, 0, ...
max values : 3039118788, Zygogynum argenteum, 13690, -1.9667, 153.985, 422.5197024, 426.9292313, 101.4610783, 726.4499222, 3756.437675, 254, 254, 4204.876009, 1324.01969, 5.413501295, ...