Extract a specific polygon from a shapefile and export it as new shapefile.
Three steps to subset a shapefile and export a new shapefile with the attributes you are interested in.
Load the package sf to load your shapefile into R
Load the package here to use your directory (in which folder is your shapefile)
Load your shapefile, be careful with your directory
Check the class, theoretically it would show sf
class(Old_shapefile)
[1] "sf" "tbl_df" "tbl" "data.frame"
Explore the contents
str(Old_shapefile)
Check the values in the column that you are interested to subset, to show unique values use the argument unique and to show them in alphabetic order use sort
Load the package tidyverse
Using the function filter you can subset your old new shapefile and get the new one
In the example we used the column comuna and the value we are interested is La Higuera, do not forget to replace those values
Check the class of your new object
class(New_shapefile)
[1] "sf" "tbl_df" "tbl" "data.frame"
Export to your selected directory