I have a dataframe latitude and longitude points in R. Using the R data science toolkit, I can assign these points to Country/State/County/City/Constituency/Neighborhood, which is useful.
I’d like to assign these points to 5 digit zip-codes (or even 9 digit zip codes!) in R or python. Is there an easy way to do this?
Edit: I found a file that contains zip code boundaries. Unfortunately, it is a .lpk file. How do I import this into R?
Edit 2: I found a shape file, which will be easier to work with.
Find a zip code shapefile somewhere (.shp format, sometimes called
ArcGIS Shapefiles).
Load it into R using the
maptoolspackage’sreadShapePolycommand.
Create a SpatialPointsDataFrame to hold the points.
Make sure your projections are correct.
Use the
sppackage’soverlaycommand to overlay the points into the polygons.You may find
cleanLatLonin the taRifx package to be helpful.