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 |
strata |
An additive |
associations |
A named |
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 |
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 |
other_summary |
A named character vector containing string templates of how results for non-numeric and non-categorical data should be presented. Defaults to |
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 |
evaluate |
Should the results of the string templates be evaluated as an |
add_n |
Should the sample size for each stratfication level be added to the result? Defaults to |
order |
Arguments passed to |
labels |
A named character vector containing the new labels. Defaults to |
levels |
A named |
format |
The format that the result should be rendered in. Must be "html", "latex", "markdown", "pandoc", or "none". Defaults to |
variableName |
Header for the variable column in the result. Defaults to |
levelName |
Header for the factor level column in the result. Defaults to |
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 |
... |
Additional arguments to pass to |
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
)