data-raw/uptake.R

library(tidyr)
library(RSocrata)
source("data-raw/helpers.R")

### UPTAKE FROM HERE:  https://data.cdc.gov/Flu-Vaccinations/Influenza-Vaccination-Coverage-for-All-Ages-6-Mont/vh55-3he6

raw <- RSocrata::read.socrata(
    "https://data.cdc.gov/resource/vh55-3he6.csv?geography=United States&vaccine=Seasonal Influenza&dimension_type=Age&$where=dimension not like '%High%'&month=5"
)

raw %>%
    # split ci to two columns
    separate(
        data = .,
        col = "X_95_ci",
        into = c("lower_ci", "upper_ci"),
        sep = " to ",
        remove = F
    ) %>%
    # remove 2009-10 because it's not a full year
    subset(
        year_season != "2009-10"
    ) %>%
    mutate(
        across(c(lower_ci, coverage_estimate), \(x) replace(x, is.na(upper_ci), NA)),
        year_season = gsub("-", "-20", year_season),
        across(c(lower_ci, upper_ci, coverage_estimate), as.numeric),
        age_group = recode_factor(dimension,
            "6 Months - 17 Years" = "0 - 17",
            "18-49 Years" = "18 - 49",
            "50-64 Years" = "50 - 64",
            "≥65 Years" = "65+"
        )
    ) %>%
    rename(
        season = "year_season",
        value = "coverage_estimate",
    ) %>%
    select(c(
        required_columns,
        population_sample_size)
    ) -> uptake

usethis::use_data(uptake,
    overwrite = T
)
QuartzSoftwareLLC/shiny.fluToolKit documentation built on April 28, 2022, 6:25 a.m.