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)
)

Arguments

data1

A data frame containing the data to summarize.

by_group

A boolean (default is FALSE) to analyse by group.

var_group

A string or NULL, the variable to group by (optional). If NULL, no grouping will be applied.

quali

A character vector, the names of categorical variables to treat as categorical in the summary table.

quanti

A character vector, the names of continuous variables to treat as continuous in the summary table.

digits

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).

Value

A gtsummary table summarizing the specified variables, grouped by var_group if provided, with customizable statistics and rounding options.

Examples

# Example usage with the iris dataset
base_table(iris, var_group = "Species")
Characteristic N = 1501
Sepal.Length
    Mean (SD) 5.8 (0.8)
    Median (Q1 ; Q3) 5.8 (5.1 ; 6.4)
    Min ; Max 4.3 ; 7.9
Sepal.Width
    Mean (SD) 3.1 (0.4)
    Median (Q1 ; Q3) 3.0 (2.8 ; 3.3)
    Min ; Max 2.0 ; 4.4
Petal.Length
    Mean (SD) 3.8 (1.8)
    Median (Q1 ; Q3) 4.4 (1.6 ; 5.1)
    Min ; Max 1.0 ; 6.9
Petal.Width
    Mean (SD) 1.2 (0.8)
    Median (Q1 ; Q3) 1.3 (0.3 ; 1.8)
    Min ; Max 0.1 ; 2.5
Species
    setosa 50 (33.3%)
    versicolor 50 (33.3%)
    virginica 50 (33.3%)
1 n (%)