This function generates a summary table from a data frame with specified
grouping and variable types. It uses the gtsummary package to create
descriptive statistics for categorical and continuous variables, with
options for customizing the rounding and labels.
base_table(
data1,
by_group = FALSE,
var_group,
quali = NULL,
quanti = NULL,
digits = list(mean_sd = 1, median_q1_q3_min_max = 1, pct = 1)
)A data frame containing the data to summarize.
A boolean (default is FALSE) to analyse by group.
A string or NULL, the variable to group by (optional). If NULL, no grouping will be applied.
A character vector, the names of categorical variables to treat as categorical in the summary table.
A character vector, the names of continuous variables to treat as continuous in the summary table.
A list, the number of decimal places to round categorical and continuous variable. Default is list(mean_sd = 1, median_q1_q3_min_max = 1, pct = 1).
A gtsummary table summarizing the specified variables,
grouped by var_group if provided, with customizable statistics
and rounding options.
# Example usage with the iris dataset
base_table(iris, var_group = "Species")
Characteristic
N = 1501
1 n (%)