add_summary.Rd
This function generates summary statistics for variables from a data frame that has been processed by add_var()
, with options to format outputs.
add_summary(
data,
add_overall = TRUE,
continuous_format = NULL,
norm_continuous_format = "{mean} ± {SD}",
unnorm_continuous_format = "{median} ({Q1}, {Q3})",
categorical_format = "{n} ({pct})",
binary_show = "last",
digit = 2
)
A data frame that has been processed by add_var()
.
Logical indicating whether to include an "Overall" summary column. TRUE
, by default.
Format string to override both normal/abnormal continuous formats. Accepted placeholders are {mean}
, {SD}
, {median}
, {Q1}
, {Q3}
.
Format string for normally distributed continuous variables. Default is "{mean} ± {SD}"
. Accepted placeholders same as continuous_format
.
Format string for non-normal continuous variables. Default is "{median} ({Q1}, {Q3})"
. Accepted placeholders same as continuous_format
.
Format string for categorical variables. Default is "{n} ({pct})"
. Accepted placeholders are {n}
and {pct}
.
Display option for binary variables:
"first"
: show only first level
"last"
: show only last level, default
"all"
: show all levels
digit A numeric determine decimal.
A data frame containing summary statistics with the following columns:
variable
: Variable name
Overall (n=X)
: Summary statistics for all data, if add_overall=TRUE
Group-specific columns named [group] (n=X)
with summary statistics
# `data` is a data frame processed by `add_var()`:
data <- add_var(iris, var = c("Sepal.Length", "Sepal.Width"), group = "Species")
# Add summary statistics
result <- add_summary(data, add_overall = TRUE)
#> ⠙ Summarizing
#> ✔ Summarizing [34ms]
#>
result <- add_summary(data, continuous_format = "{mean}, ({SD})")
#> ⠙ Summarizing
#> ✔ Summarizing [30ms]
#>