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,
show_missing_data,
by_group = FALSE,
var_group,
quali = NULL,
quanti = NULL,
stat_var_quanti = c("{mean} ({sd})", "{median} ({p25}; {p75})", "{min}; {max}"),
digits = list(r_quanti = 1, r_quali = 1)
)A gtsummary table summarizing the specified variables,
grouped by var_group if provided, with customizable statistics
and rounding options.
A data frame containing the data to summarize.
Should the missing data be displayed. Can be either :
FALSE: No missing data displayed
TRUE(default): Missing data displayed
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 character vector specifying the statistics to display for continuous variables. Default is c("{mean} ({sd})", "{median} ({p25}; {p75})", "{min}; {max}").
A list, the number of decimal places to round categorical and continuous variable. Default is list(r_quanti = 1, r_quali = 1)
# Example usage with the iris dataset
base_table(iris, var_group = "Species", show_missing_data = TRUE)
Run the code above in your browser using DataLab