View source: R/rollSummaryXDays.R
rollSummaryXDays | R Documentation |
Given a formatted variable table, this function calculates the rolling averages and totals for the specified columns over a specified number of days.
rollSummaryXDays(df, numDays = 7, varTable)
df |
Input data.frame to be summarized |
numDays |
The number of days to do the summary over. Defaults at 7 days. |
varTable |
A formatted data.frame containing variable, Avg, Total, CalcString columns. See details for more information. |
The format of varTable:
Variable names that you want to create summaries for
TRUE/FALSE on whether X day averages should be caclulated for the given variable
TRUE/FALSE on whether X day totals should be caclulated for the given variable
Used for pre-summary mutations to create the variables needed; see mutateCalcString
. If none are needed, supply a vector of NA's
## Not run: # Load in CDT and Hospital Base Data cdtData <- downloadBaseData(type = "CDT") hospData <- downloadBaseData(type = "Hospital") # Combine Hospital and CDT Base Data cdtHospData <- dplyr::full_join(cdtData, hospData, by = c("GeoID", "Date")) %>% marcR::coalesceJoin() %>% dplyr::mutate(CovidNew = CovidNew24HConfirmed + CovidNew24HSuspected) %>% dplyr::select( Jurisdiction, State, GeoID, Region, Date, CasesNew, CasesTotal, DeathsNew, DeathsTotal, TestsNew, TestsTotal, Population, HospitalsReporting, HospitalsTotal, BedsTotal, BedsUsed, BedsAvailable, BedsICUTotal, BedsICUUsed, BedsICUAvailable, CovidTotal, CovidNew, CovidICUTotal, CovidICUConfirmed, CovidICUSuspected, VentilatorsTotal, VentilatorsUsed, VentilatorsAvailable, CovidVentilatorsUsed) # Calculate Rolling Average Tables varTable <- tibble::tribble( ~variable, ~Avg, ~Total, ~CalcString, "CasesNew", TRUE, TRUE, NA, "DeathsNew", TRUE, TRUE, NA, "TestsNew", TRUE, TRUE, NA, "CovidNew", TRUE, TRUE, NA, "CovidTotal", TRUE, FALSE, NA, "BedsUsedOther", TRUE, FALSE, "BedsUsed - CovidTotal", "BedsAvailable", TRUE, FALSE, NA, "CovidICUTotal", TRUE, FALSE, NA, "BedsICUUsedOther", TRUE, FALSE, "BedsICUUsed - CovidICUTotal", "BedsICUAvailable", TRUE, FALSE, NA, "CovidVentilatorsUsed", TRUE, FALSE, NA, "VentilatorsUsedOther", TRUE, FALSE, "VentilatorsUsed - CovidVentilatorsUsed", "VentilatorsAvailable", TRUE, FALSE, NA, "HospitalsReporting", TRUE, TRUE, NA, "HospitalsTotal", TRUE, TRUE, NA ) cdtHosp7DayRollingData <- rollSummaryXDays(df = cdtHospData, numDays = 7, varTable = varTable) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.