Skip to content

Instantly share code, notes, and snippets.

@erikgregorywebb
Last active November 17, 2020 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikgregorywebb/10bea41e9977eeebccf9555b5f27f167 to your computer and use it in GitHub Desktop.
Save erikgregorywebb/10bea41e9977eeebccf9555b5f27f167 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(zipcode)
library(lubridate)
# import dallas zipcodes
url = 'https://raw.githubusercontent.com/erikgregorywebb/datasets/master/dallas-metro-zipcodes.csv'
download.file(url, 'dallas-metro-zipcodes.csv')
dallas_zipcodes = read_csv('dallas-metro-zipcodes.csv')
# import realtor.com
url = 'https://econdata.s3-us-west-2.amazonaws.com/Reports/Core/RDC_Inventory_Core_Metrics_Zip_History.csv'
download.file(url, 'realtor-inventory-zip.csv')
rltr = read_csv('realtor-inventory-zip.csv')
# filter for dallas metro area
rltr_dallas = rltr %>% filter(postal_code %in% (dallas_zipcodes %>% pull(zipcode)))
# merge in extra zipcode detials
rltr_dallas = left_join(x = rltr_dallas, y = dallas_zipcodes, by = c('postal_code' = 'zipcode'))
# preview
glimpse(rltr_dallas)
# merge in city frequency counts for filtering
rltr_dallas = left_join(x = rltr_dallas, y = dallas_zipcodes %>% group_by(city) %>% count(sort = T) %>% rename(city_count = n), by = 'city')
# clean date field
rltr_dallas = rltr_dallas %>%
mutate(month_date_yyyymm = lubridate::ymd(paste(month_date_yyyymm, '01', sep = '')))
# export for use in Tableau
write_csv(rltr_dallas, 'rltr_dallas.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment