Sum a Stratified Variable
summarise_strat_var(df, vars, strat = NULL, new_var = "sum")
A dataframe of model output.
A character vector containing the unstratified variables to summarise
The number of stratifications present in the data set
The name of the summarised variable
Returns the original dataframe with an additional summarised variable
summarise_var_by_strat
df <- dplyr::mutate(iris, Petal.Length1 = Petal.Length, Petal.Length2 = Petal.Length)
df <- tibble::as_tibble(df)
summarise_strat_var(df, vars = c("Petal.Length"), strat = 2, new_var = "sum")
#> # A tibble: 150 × 8
#> sum Sepal.Length Sepal.Width Petal.Length Petal.W…¹ Species Petal…² Petal…³
#> <dbl> <dbl> <dbl> <dbl> <dbl> <fct> <dbl> <dbl>
#> 1 2.8 5.1 3.5 1.4 0.2 setosa 1.4 1.4
#> 2 2.8 4.9 3 1.4 0.2 setosa 1.4 1.4
#> 3 2.6 4.7 3.2 1.3 0.2 setosa 1.3 1.3
#> 4 3 4.6 3.1 1.5 0.2 setosa 1.5 1.5
#> 5 2.8 5 3.6 1.4 0.2 setosa 1.4 1.4
#> 6 3.4 5.4 3.9 1.7 0.4 setosa 1.7 1.7
#> 7 2.8 4.6 3.4 1.4 0.3 setosa 1.4 1.4
#> 8 3 5 3.4 1.5 0.2 setosa 1.5 1.5
#> 9 2.8 4.4 2.9 1.4 0.2 setosa 1.4 1.4
#> 10 3 4.9 3.1 1.5 0.1 setosa 1.5 1.5
#> # … with 140 more rows, and abbreviated variable names ¹Petal.Width,
#> # ²Petal.Length1, ³Petal.Length2