I want to remove NAs from "SpatialPolygonsDataFrame". Traditional df approach and subsetting (mentioned above) does not work here, because it is a different type of a df. I tried to remove NAs as for traditional df and failed. The firsta answer, which also good for traditional df, does not work for spatial. I combine csv and a shape file below
countries <- readOGR(".","ne_50m_admin_0_countries")
I receive
class(data_pg_df)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"
When I try to create a simple leaflet map, NAs create a problem.
[1] NA NA NA NA NA NA NA NA NA NA NA NA
[13] NA NA NA NA NA NA NA NA NA "SSA" "SSA" NA
[25] NA NA NA NA NA NA NA NA NA NA NA NA
I tried to remove NAs with sp.na.omit() , but receive an error
Error in sp.na.omit(data_pg_df) : could not find function "sp.na.omit"
Shape also does not work. My goal is remove NAs and have a clean map with polygons
Thanks!
have you loaded the ' spatialEco
' library? after you loaded the library, try this
df <- sp.na.omit(data_pg_df, margin = 1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.