I'm working on a Shiny app for R and I'm trying to use the RDSTK package to reverse geocode a list of lat/lon pairs and get the CITY from the json results and save it to a list. The workflow is:
- SQLDF to select all records within a date range.
- Reverse geocode records and add column to data frame with the specific city.
- Use SQLDF again to get counts by city.
I'm having a lot of trouble understanding how to take the JSON output, convert it to data frame, then cbind it back to the original data frame. Any help would be much appreciated! See below code for reference:
Data frame:
df <- data.frame(lat=c(34.048381, 37.757836, 40.729855, 42.356391),
lon=c(-118.266164, -122.441033, -73.987921, -71.062307))
I was able to extract the city from the returned JSON list, but I can't for the life of me, figure out how to do it multiple times for a larger list of lat/lon pairs. Searching through stackoverflow mainly results in dstk outside of R.
My ideal output would be:
lat lon city
34.048381 -118.266164 Los Angeles
37.757836 -122.441033 San Francisco
40.729855 -73.987921 New York
42.356391 -71.062307 Boston
I've also tried this example: R: How to GeoCode a simple address using Data Science Toolbox though I can't seem to re-engineer it for coordinates2politics.
Any input?