sum_stat: Summarize Continuous and Categorical Variables with Optional Grouping
Description
sum_stat provides a summary of both continuous and categorical variables in a dataset.
Continuous variables can be summarized using mean (SD) or median (IQR), optionally with 95% confidence intervals.
Categorical variables are summarized as counts and percentages, optionally with confidence intervals.
Summaries can also be generated by a grouping variable, and a narrative interpretation is optionally printed.
A flextable object displaying the summarized variables, optionally including confidence intervals and group comparisons.
Arguments
data
A data.frame or tibble containing the variables to summarize.
by
Optional. A single variable name (as string) to group the summary by.
statistic
Character string indicating how to summarize continuous variables. Options are "mean_sd" (default) or "med_iqr".
percent
Character string specifying how percentages should be calculated for categorical variables: "col" (column-wise), "row" (row-wise), or "none" (no percentage). Default is "col".
ci
Logical. If TRUE, 95% confidence intervals are included in the summary for continuous and categorical variables. Default is FALSE.
conf
Numeric. Confidence level for CI calculation (between 0 and 1). Default is 0.95.
report
Logical. If TRUE, prints a narrative summary of the variables. Default is TRUE.
# Basic summary of iris datasetsum_stat(iris, ci = FALSE, report = TRUE)
# Summary of CO2 dataset by 'Treatment' with CIsum_stat(CO2, by = "Treatment", ci = TRUE, report = TRUE, percent = "row")