Get mean and standard deviation of variables by group

make_mean_std_dev_by_group_table(data, group_column, columns, total_row = TRUE)

Arguments

data

A data.frame with the data you want to make the table from.

group_column

A string with the name of the variable you are grouping by

columns

A string or vector of strings for the variables you want to get the mean and standard deviation for.

total_row

A boolean (default TRUE) for whether to include a row a the bottom for the overall mean and standard deviation (i.e. not by group).

Value

A data.frame with the first column showing the category grouped by. Then one column for each variable you want the mean and standard deviation for. Will give the mean and standard deviation as a single string with the standard deviation in parentheses.

Examples

make_mean_std_dev_by_group_table(mtcars, "gear", c("mpg", "disp"))
#>    gear          mpg            disp
#> 1  3.00 16.11 (3.37)  326.30 (94.85)
#> 2  4.00 24.53 (5.28)  123.02 (38.91)
#> 3  5.00 21.38 (6.66) 202.48 (115.49)
#> 4 Total 20.09 (6.03) 230.72 (123.94)