Created
May 27, 2021 15:17
-
-
Save xenatisch/d2113d97055b7dd08649eeac33d6e090 to your computer and use it in GitHub Desktop.
Convert APIv2 response for the age demographics data from the UK Coronavirus Dashboard to unstacked (wide) format
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(dplyr) | |
library(tidyr) | |
data <- read.csv("https://api.coronavirus.data.gov.uk/v2/data?areaType=ltla&metric=newCasesBySpecimenDateAgeDemographics&format=csv") | |
# Add the age bands you want to exclude | |
excluded_age_bands <- c("unassigned", "60+", "00_59") | |
# Add area codes you want to include - leave blank for everything. | |
included_area_codes <- c() | |
if (length(included_area_codes) == 0) { | |
included_area_codes <- data$areaCode | |
} | |
wideData <- data %>% | |
filter(!age %in% target) %>% | |
filter(areaCode %in% included_area_codes) %>% | |
pivot_wider( | |
names_from = "age", | |
values_from = c(cases, rollingSum, rollingRate), | |
names_sep = "-" | |
) | |
print(head(wideData)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment