I have a SpatialPixelsDataFrame (sp object) for which I wish to remove all pixels containing NA values in the @data slot. I am aware of this post but the function throws an error. The final result should equally be a SpatialPixelsDataFrame.
Here is a reproducible example:
library(sp)
library(sf)
library(raster)
library(SpatialEco)
m <- raster::raster(ncol=100, nrow=100) # create raster
m[] <- runif(ncell(m))
m[m < 0.2] <- NA # simulate NAs
spdf <- as(m, "SpatialPixelsDataFrame") # transform to SpatialPixelsDataFrame
spdf_new <- sp.na.omit(st_as_sf(spdf), margin = 1)
Warning message
Function is deprecated because stats::na.omit operates on
sf class objects
Thanks in advance!