R for Spatial Statistics


Working with Vector Data in sf

sf is a new package and apepars to be the leading contender to replace rgdal and sp. sf reads and writes shapefiles and also has a large number of vector transforms available (see resources at the bottom of the page).

Reading and Displaying Data

The code below will read a shapefile into a data table.

# Load library
library("tibble") # required for read (at least).  This installs about 10 other libraries


# Loads data table
TheCities <- read_sf(FilePath)


Because we now have a data frame, all of the other functions such as nrow() and ncol() work with the data.

Additional Resources

Simple Features for R - website for SF with great quick reference.