This function is a lightweight wrapper to dplyr's summarize function. It can be used to calculate any descriptive or summary statistic for any variable in the data set. Optionally, a by grouping variable can be used, and then the summary statistics are calculated for each subgroup defined by the different values of the by variable.

describe(data, by = NULL, ...)

Arguments

data

A data frame

by

A grouping variable. If included, the data will be grouped by the values of the by variable before the summary statistics are applied.

...

Arguments of functions applied to variables, e.g. avg = mean(x).

Value

A tibble data frame with each row providing descriptive statistics for selected variables for each value of the grouping by variable.

Examples

describe(faithfulfaces, avg = mean(faithful), stdev = sd(faithful))
#> # A tibble: 1 × 2
#>     avg stdev
#>   <dbl> <dbl>
#> 1  5.14 0.957
describe(faithfulfaces, by = face_sex, avg = mean(faithful), stdev = sd(faithful))
#> # A tibble: 2 × 3
#>   face_sex   avg stdev
#>   <chr>    <dbl> <dbl>
#> 1 female    5.55 0.802
#> 2 male      4.75 0.932