Descriptive summary table with group comparisons (Table 1)
Source:R/tbl_descriptive.R
tbl_descriptive.RdProduces a descriptive/Table 1-style summary of a data frame, with optional
group comparisons. Formatting defaults are inherited from clerk_options().
Arguments
- data
A data frame.
- group
<
tidy-select> Grouping variable.- vars
<
tidy-select> Variables to include. Defaults to all columns exceptgroup.- domains
A named list mapping variable names to domain/section labels. An entry may itself be a named list to create a nested sub-section within a domain (e.g. repeated timepoints) – see
vignette("formatting-options").- log_vars
Character vector of log-transformed variable names.
- digits
Integer. Decimal places for continuous variables.
- p_digits
Integer. Decimal places for p-values.
- p_threshold
Numeric. P-values below this are shown as
"< {threshold}". Inherits fromclerk_options()$p_thresholdifNULL.- p_style
Character. P-value style (
"apa","plain","stars","stars_p").- stars
Logical. Append significance stars.
- fdr
Logical. Apply BH FDR correction (default
FALSE).- fdr_ns
Logical. Replace non-surviving FDR p-values with
"ns".- fdr_alpha
Numeric. Alpha level for FDR survival (BH-adjusted p).
- domain_other
Character string. Label for variables not assigned to any domain. Default
""(blank). Inherits fromclerk_options()$domain_other.- overall
Logical. Include an overall column (default
TRUE).- output
Character string. One of
"gt","html", or"latex".
Examples
tbl_descriptive(
clerk_example,
group = sex,
domains = list(
"Metabolic" = c("hdl", "glucose", "bmi"),
"Cognitive" = c("tmt_time", "verbal_fluency"),
"Mental health"= c("bdi", "panas_neg")
),
log_vars = "tmt_time",
output = "gt"
) |> clerk_render(title = "Table 1. Sample characteristics by sex")