This is a wrapper around aggregate
function in base R to obtain mean, median, standard deviation and count for quantitative variable(s) grouped by one or more factors. More than one column containing of quantitative variables can be passed on, and summaries for each is provided with column names with a .
.
table_summary(data, Ycol, ByGroup)
name of the data table.
name of one column (in quotes) or a vector of column names containing the numerical variable to be summarised.
name of one column (in quotes) or a vector of column names containing the grouping factors
this function takes in a data.frame or tibble and returns a data.frame or tibble.
table_summary(Ycol = "cty",
ByGroup = c("fl", "drv"),
data = mpg)
#> fl drv cty.Mean cty.Median cty.SD cty.Count
#> 1 d 4 15.500000 15.5 2.1213203 2
#> 2 e 4 9.333333 9.0 0.8164966 6
#> 3 p 4 16.000000 16.5 2.9735678 20
#> 4 r 4 14.253333 14.0 2.4883150 75
#> 5 c f 24.000000 24.0 NA 1
#> 6 d f 32.333333 33.0 3.0550505 3
#> 7 e f 11.000000 11.0 NA 1
#> 8 p f 19.240000 19.0 2.1071308 25
#> 9 r f 19.789474 19.0 3.0213277 76
#> 10 e r 11.000000 11.0 NA 1
#> 11 p r 14.571429 15.0 1.7182494 7
#> 12 r r 14.058824 14.0 2.3577157 17