Sum a Stratified Variable
summarise_strat_var(df, vars, strat = NULL, new_var = "sum")
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 |
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 x 8 #> sum Sepal.Length Sepal.Width Petal.Length Petal.Width Species Petal.Length1 #> <dbl> <dbl> <dbl> <dbl> <dbl> <fct> <dbl> #> 1 2.8 5.1 3.5 1.4 0.2 setosa 1.4 #> 2 2.8 4.9 3 1.4 0.2 setosa 1.4 #> 3 2.6 4.7 3.2 1.3 0.2 setosa 1.3 #> 4 3 4.6 3.1 1.5 0.2 setosa 1.5 #> 5 2.8 5 3.6 1.4 0.2 setosa 1.4 #> 6 3.4 5.4 3.9 1.7 0.4 setosa 1.7 #> 7 2.8 4.6 3.4 1.4 0.3 setosa 1.4 #> 8 3 5 3.4 1.5 0.2 setosa 1.5 #> 9 2.8 4.4 2.9 1.4 0.2 setosa 1.4 #> 10 3 4.9 3.1 1.5 0.1 setosa 1.5 #> # … with 140 more rows, and 1 more variable: Petal.Length2 <dbl>