Create a table showing the mean, median, and mode of a certain column

make_mean_median_mode_table_by_group(
  data,
  group_column,
  data_column,
  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

data_column

A string for the variable you want to get the mean, median, and mode from, Variable should be numeric.

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 the mean, one column for the median, and one column for the mode.

Examples

make_mean_median_mode_table_by_group(mtcars, "gear", "mpg")
#>    gear  mean median                                   mode .median
#> 1     3 16.11   15.5                             10.4, 15.2    15.5
#> 2     4 24.53   22.8                               21, 22.8    22.8
#> 3     5 21.38   19.7                                      -    19.7
#> 4 Total 20.09   19.2 10.4, 15.2, 19.2, 21, 21.4, 22.8, 30.4      NA