I am looking for a subset of SpatialPolygonsDataFrame by attribute, but I want to allow it to return an empty SpatialPolygonsDataFrame.
If we consider objects of type SpatialPolygonsDataFrame, such as data.frames, as discussed here , we should be able to work and work with empty objects.
I am interested because I want to include this in a function that can try a subset of an attribute that essentially will not select any functions.
owd <- getwd()
setwd(system.file("shapes", package = "maptools"))
library(maptools)
nc90 <- readShapeSpatial("co37_d90")
setwd(owd)
nc90@data[nc90@data$AREA>0.15,]
bigctys <- nc90[nc90@data$AREA>0.15,]
nc90@data[nc90@data$AREA>0.25,]
bigestctys <- nc90[nc90@data$AREA>0.25,]
Is there any way to make this work? If not, is there a way to initialize an empty SpatialPolygonsDataFrame object? The future actions that I want to perform on such an object are related to plotting on an existing map, so I would like the image to be created in any case, even if it is empty.
source
share