Last active
November 17, 2020 17:29
-
-
Save erikgregorywebb/10bea41e9977eeebccf9555b5f27f167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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