Created
July 28, 2021 02:27
-
-
Save mtdukes/54d198f4b336216824205599d794f885 to your computer and use it in GitHub Desktop.
Simple script to import data on COVID-19 from the CDC website.
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
''' | |
A simple script to grab COVID data from the CDC | |
hastily typed by @mtdukes | |
Follow the Twitter thread for more detail: | |
https://twitter.com/mtdukes/status/1420191934979657731 | |
''' | |
#install your packages, if you haven't already | |
install.packages('jsonlite') | |
install.packages('tidyverse') | |
#load libraries into your workspace | |
library('jsonlite') | |
library('tidyverse') | |
#load json data from the CDC URL | |
county_data <- fromJSON( | |
'https://covid.cdc.gov/covid-data-tracker/COVIDData/getAjaxData?id=integrated_county_latest_external_data', | |
simplifyVector = TRUE | |
#the json file includes another item that we don't want, so specify what we're interested in | |
)['integrated_county_latest_external_data'] %>% | |
#turn it into a dataframe instead of a weird matrix | |
as.data.frame() %>% | |
#clean up the column names | |
rename_with( ~ tolower( gsub('integrated_county_latest_external_data\\.' ,'', . ) ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment