desc_table {desctable}R Documentation

Generate a statistics table

Description

Generate a statistics table with the chosen statistical functions, nested if called with a grouped dataframe.

Usage

desc_table(data, ..., .auto, .labels)

## Default S3 method:
desc_table(data, ..., .auto, .labels)

## S3 method for class 'data.frame'
desc_table(data, ..., .labels = NULL, .auto = stats_auto)

## S3 method for class 'grouped_df'
desc_table(data, ..., .auto = stats_auto, .labels = NULL)

Arguments

data

The dataframe to analyze

...

A list of named statistics to apply to each element of the dataframe, or a function returning a list of named statistics

.auto

A function to automatically determine appropriate statistics

.labels

A named character vector of variable labels

Value

A simple or grouped descriptive table

Stats

The statistical functions to use in the table are passed as additional arguments. If the argument is named (eg. N = length) the name will be used as the column title instead of the function name (here, N instead of length).

Any R function can be a statistical function, as long as it returns only one value when applied to a vector, or as many values as there are levels in a factor, plus one.

Users can also use purrr::map-like formulas as quick anonymous functions (eg. Q1 = ~ quantile(., .25) to get the first quantile in a column named Q1)

If no statistical function is given to desc_table, the .auto argument is used to provide a function that automatically determines the most appropriate statistical functions to use based on the contents of the table.

Labels

.labels is a named character vector to provide "pretty" labels to variables.

If given, the variable names for which there is a label will be replaced by their corresponding label.

Not all variables need to have a label, and labels for non-existing variables are ignored.

labels must be given in the form c(unquoted_variable_name = "label")

Output

The output is either a dataframe in the case of a simple descriptive table, or nested dataframes in the case of a comparative table.

See Also

stats_auto

IQR

percent

Other desc_table core functions: desc_output(), desc_tests()

Examples

iris %>%
  desc_table()

# Does the same as stats_auto here
iris %>%
  desc_table("N"      = length,
             "Min"    = min,
             "Q1"     = ~quantile(., .25),
             "Med"    = median,
             "Mean"   = mean,
             "Q3"     = ~quantile(., .75),
             "Max"    = max,
             "sd"     = sd,
             "IQR"    = IQR)

# With grouping on a factor
iris %>%
  group_by(Species) %>%
  desc_table(.auto = stats_auto)

[Package desctable version 0.3.0 Index]