univariate_table {cheese}R Documentation

Create a custom descriptive table for a dataset

Description

Produces a formatted table of univariate summary statistics with options allowing for stratification by one or more variables, computing of custom summary/association statistics, custom string templates for results, etc.

Usage

univariate_table(
    data,
    strata = NULL,
    associations = NULL,
    numeric_summary = c(Summary = "median (q1, q3)"),
    categorical_summary = c(Summary = "count (percent%)"),
    other_summary = NULL,
    all_summary = NULL,
    evaluate = FALSE,
    add_n = FALSE,
    order = NULL,
    labels = NULL,
    levels = NULL,
    format = c("html", "latex", "markdown", "pandoc", "none"),
    variableName = "Variable",
    levelName = "Level",
    sep = "_",
    fill_blanks = "",
    caption = NULL,
    ...
)

Arguments

data

A data.frame.

strata

An additive formula specifying stratification columns. Columns on the left side go down the rows, and columns on the right side go across the columns. Defaults to NULL.

associations

A named list of functions to evaluate with column strata and each variable. Defaults to NULL. See univariate_associations.

numeric_summary

A named vector containing string templates of how results for numeric data should be presented. See details for what is available by default. Defaults to c(Summary = "median (q1, q3)").

categorical_summary

A named vector containing string templates of how results for categorical data should be presented. See details for what is available by default. Defaults to c(Summary = "count (percent%)").

other_summary

A named character vector containing string templates of how results for non-numeric and non-categorical data should be presented. Defaults to NULL.

all_summary

A named character vector containing string templates of additional results applying to all variables. See details for what is available by default. Defaults to NULL.

evaluate

Should the results of the string templates be evaluated as an R expression after filled with their values? See absorb for details. Defaults to FALSE.

add_n

Should the sample size for each stratfication level be added to the result? Defaults to FALSE.

order

Arguments passed to forcats::fct_relevel for reordering the variables. Defaults to NULL

labels

A named character vector containing the new labels. Defaults to NULL

levels

A named list of named character vectors containing the new levels. Defaults to NULL

format

The format that the result should be rendered in. Must be "html", "latex", "markdown", "pandoc", or "none". Defaults to "html".

variableName

Header for the variable column in the result. Defaults to "Variable".

levelName

Header for the factor level column in the result. Defaults to "Level".

sep

Delimiter to separate summary columns. Defaults to "_".

fill_blanks

String to fill in blank spaces in the result. Defaults to "".

caption

Caption for resulting table passed to knitr::kable. Defaults to NULL.

...

Additional arguments to pass to descriptives.

Value

A table of summary statistics in the specified format. A tibble::tibble is returned if format = "none".

Author(s)

Alex Zajichek

Examples


#Set format
format <- "pandoc"

#Default summary
heart_disease %>%
    univariate_table(
      format = format
    )

#Stratified summary
heart_disease %>%
    univariate_table(
        strata = ~Sex,
        add_n = TRUE,
        format = format
    )

#Row strata with custom summaries with
heart_disease %>%
    univariate_table(
        strata = HeartDisease~1,
        numeric_summary = c(Mean = "mean", Median = "median"),
        categorical_summary = c(`Count (%)` = "count (percent%)"),
        categorical_types = c("factor", "logical"),
        add_n = TRUE,
        format = format
    )
    

[Package cheese version 0.1.2 Index]