I have a list of locations that contains a city, state, zip, latitude and longitude for each location.
I separately have a list of economic indicators at the county level. I've played with the zipcode
package, the ggmap
package, and several other free geocoding websites including the US Gazeteer files, but can't seem to find a way to match the two pieces.
Are there currently any packages or other sources that do this?
A simple option is to use the
geocode()
function inggmap
, with the optionoutput="more"
oroutput="all
.This can take flexible input, such as the address or lat/lon, and returns Address, city, county, state, country, postal code, etc, as a list.
Another solution is to use a census shapefile, and the same
over()
command from the question. I ran into a problem using the maptools base map: because it uses the WGS84 datum, in North America, points that were within a few miles of the coast were mapped incorrectly and about 5% of my data set did not match up.try this, using the
sp
package and Census TIGERLine shape filesMatching Zipcodes to Counties is difficult. (Certain zip codes span more than one county and sometimes more than one state. For example 30165)
I am not aware of any specific R package that can match these up for you.
However, you can get a nice table from the Missouri Census Data Center.
You can use the following for data extraction: http://bit.ly/S63LNU
A sample output might look like:
Note the County2. metadata explanation can be found here.
See also ANSI County codes http://www.census.gov/geo/www/ansi/ansi.html
I ended up using the suggestion from
JoshO'Brien
mentioned above and found here.I took his code and changed
state
tocounty
as shown here:I think the package "noncensus" is helpful.
corresponding is what I use to match zipcode with county