Skip to content

Instantly share code, notes, and snippets.

@WalkerHarrison
Last active April 24, 2017 06:55
Show Gist options
  • Save WalkerHarrison/33fc930d85fafd5c6a5613721d8f86b4 to your computer and use it in GitHub Desktop.
Save WalkerHarrison/33fc930d85fafd5c6a5613721d8f86b4 to your computer and use it in GitHub Desktop.
library(XML)
library(ggplot2)
library(ggmap)
library(RSocrata)
url_trees <- 'https://data.cityofnewyork.us/resource/nwxe-4ae8.csv'
url_zips <- 'http://zipatlas.com/us/ny/brooklyn/zip-code-comparison/median-household-income.htm'
trees <-read.socrata(url_trees)
trees <- subset(trees, boroname == 'Brooklyn')
trees$tree_dbh <- as.numeric(trees$tree_dbh)
neighborhoods <- readHTMLTable(url_zips, header=T, which=1, stringsAsFactors=F)
neighborhoods <- neighborhoods[complete.cases(neighborhoods), c(2,5,6)]
neighborhoods <- neighborhoods[-1, ]
names(neighborhoods) <- c("zipcode", "population", "income")
neighborhoods$population <- as.numeric(gsub("[$,]", "", neighborhoods$population))
neighborhoods$income <- as.numeric(gsub("[$,]", "", neighborhoods$income))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment