Learn R Programming

dentomedical (version 0.2.0)

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.

Usage

sum_stat(
  data,
  by = NULL,
  statistic = "mean_sd",
  percent = "col",
  ci = FALSE,
  conf = 0.95,
  report = FALSE
)

Value

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.

Examples

Run this code
# Basic summary of iris dataset
sum_stat(iris, ci = FALSE, report = TRUE)

# Summary of CO2 dataset by 'Treatment' with CI
sum_stat(CO2, by = "Treatment", ci = TRUE, report = TRUE, percent = "row")

Run the code above in your browser using DataLab