This question already has an answer here:
To simplify my problem, I'm gonna start at the source instead of explaining my full-map problem.
I have a shapefile of Ethiopia pulled from GADM (can be downloaded here). A lot of the attribute columns are unnecessary and just create extra clunkiness as I perform clips/joins/etc. with the shapefile. So I want to remove all but the first 4 columns. Doing this seems easy enough, and I tried and succeeded with this bit of code:
library(rgdal) #read in shapefile eth <- readOGR(dsn = "D:/Mapping-R/Ethiopia", layer = "ETH_adm0") #subset data/remove columns eth <- eth@data[, -(5:67)]
This does indeed leave me only with the first 4 columns, but it also makes the object a regular data frame rather than a spatial data frame ready for mapping. So how do I remove these unwanted columns while maintaining status of SPDF?