describe_across.RdThis function is a wrapper to dplyr's summarize used with the
across function. For each variable in a set of variables, calculate each
summary statistic from a list of summary statistic functions. Optionally,
group the variables by a grouping variable, and then calculate the
statistics. Optionally, the tibble that is returned by default, which is in a
wide format, can be pivoted to a long format.
describe_across(data, variables, functions, by = NULL, pivot = FALSE)A data frame
A vector of variables in data
A list of summary statistic function. If it is named list, which is recommended, the names of the functions will be used to make the names of the returned data frame.
A grouping variable. If included, the data will be grouped by the values of the
by variable before the summary statistics are applied.
A logical variable indicating if the wide format da
A tibble data frame. If pivot = F, which is the default, the data
frames contains one row per value of the by variable, or just one row overall
if there is no by variable. If pivot = T, there will be k + 1 columns
if there is no by variable, or k + 2 columns if there is a by variable,
where k is the number of functions.
describe_across(faithfulfaces,
variables = c(trustworthy, faithful),
functions = list(avg = mean, stdev = sd),
pivot = TRUE)
#> # A tibble: 2 × 3
#> variable avg stdev
#> <chr> <dbl> <dbl>
#> 1 trustworthy 4.32 0.791
#> 2 faithful 5.14 0.957
describe_across(faithfulfaces,
variables = c(trustworthy, faithful),
functions = list(avg = mean, stdev = sd),
by = face_sex)
#> # A tibble: 2 × 5
#> face_sex trustworthy_avg trustworthy_stdev faithful_avg faithful_stdev
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 female 4.44 0.742 5.55 0.802
#> 2 male 4.21 0.822 4.75 0.932
describe_across(faithfulfaces,
variables = c(trustworthy, faithful),
functions = list(avg = mean, stdev = sd),
by = face_sex,
pivot = TRUE)
#> # A tibble: 4 × 4
#> face_sex variable avg stdev
#> <chr> <chr> <dbl> <dbl>
#> 1 female trustworthy 4.44 0.742
#> 2 female faithful 5.55 0.802
#> 3 male trustworthy 4.21 0.822
#> 4 male faithful 4.75 0.932