create_descriptive_table: Format descriptive statistics tables

View source: R/descriptive-tables.R

create_descriptive_tableR Documentation

Format descriptive statistics tables

Description

Construct nicely formatted descriptive statistics tables (mean/sd, n/percent).

Usage

create_descriptive_table(
  df,
  continuous = NULL,
  discrete = NULL,
  multiresponse = NULL,
  output = c(names(continuous), names(discrete), names(multiresponse)),
  by = NULL,
  value_continuous = mean_sd(.mean, .sd, accuracy = 0.1),
  value_discrete = n_percent(.n, .proportion),
  total = !is.null(by)
)

Arguments

df

A data frame containing the variables to describe.

continuous, discrete

Character vectors of continuous and discrete variables for which to calculate descriptive statistics. Can be named, in which case the provided names will be used in place of variable names in the first column of the table.

multiresponse

List of character vectors, each specifying the individual variables making up a combined multiple-response variable. Should be named, with the names giving the variable names to be used for the combined variables.

output

(optional) Character vector of variables to include in the table (and their order). Elements should be the names of elements of continuous, discrete, and multireponse. Default is to report all variables from continuous, discrete, and multiresponse, in that order.

by

(optional) A grouping variable (as a character string) to split the sample. Default is to report for the entire sample.

value_continuous

(optional) An expression describing how to format the outcome values for continuous variables. Can refer to mean/sd/min/lq/median/uq/max as .mean, .sd, etc, and the name of the variable being formatted as .variable. Default is to report mean (SD) to one decimal place.

value_discrete

(optional) An expression describing how to format the outcome values for discrete variables. Can refer to n/proportion as .n, .proportion, and the name of the variable being formatted as .variable. Default is to report n (percentage) to zero decimal places.

total

(optional) Logical value; should a 'total' (full sample) column be included? Default is TRUE if by is specified, FALSE otherwise. Can also be a character string giving the column name to use for the total column (default is 'Entire sample').


uo-cmor/formattr documentation built on Sept. 13, 2023, 10:46 p.m.