R/summarise_var_by_strat.R
summarise_var_by_strat.Rd
Sum a Stratified Variable by Stratification Level
summarise_var_by_strat(df, vars, strat = NULL, new_var, summary_var = FALSE)
df | A dataframe of model output. |
---|---|
vars | A character vector containing the unstratified variables to summarise |
strat | The number of stratifications present in the data set |
new_var | The name of the summarised variable |
summary_var | A logical (defaults to |
An updated data frame containing the summarised variable for each stratified level and for the whole population.
Takes compartmental infectious disease output and adds summary statistics for each stratified population, optionally adding a final summary statistic for the whole population.
summarise_var_by_strat
#> # A tibble: 1 x 3 #> C A B #> <dbl> <dbl> <dbl> #> 1 3 1 2df <- data.frame(A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) summarise_var_by_strat(df, vars = c("A", "B"), strat = 3, new_var = "C")#> # A tibble: 1 x 9 #> C1 C2 C3 A1 B1 A2 B2 A3 B3 #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 2 2 2 1 1 1 1 1 1#> # A tibble: 1 x 10 #> C C1 C2 C3 A1 B1 A2 B2 A3 B3 #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 6 2 2 2 1 1 1 1 1 1