describe_across: Apply multiple descriptive functions to multiple variables

Description Usage Arguments Value Examples

View source: R/descriptive-utils.R

Description

This 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.

Usage

1
describe_across(data, variables, functions, by = NULL, pivot = FALSE)

Arguments

data

A data frame

variables

A vector of variables in data

functions

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.

by

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

pivot

A logical variable indicating if the wide format da

Value

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
describe_across(faithfulfaces, 
                variables = c(trustworthy, faithful), 
                functions = list(avg = mean, stdev = sd),
                pivot = TRUE)
describe_across(faithfulfaces, 
                variables = c(trustworthy, faithful), 
                functions = list(avg = mean, stdev = sd), 
                by = face_sex)
describe_across(faithfulfaces, 
                variables = c(trustworthy, faithful), 
                functions = list(avg = mean, stdev = sd), 
                by = face_sex,
                pivot = TRUE)

psyntur documentation built on Sept. 15, 2021, 5:07 p.m.