Skip to contents

Table 1 (baseline characteristics) stratified by group

Usage

table1(
  data,
  group_col = NULL,
  continuous_vars = NULL,
  categorical_vars = NULL,
  continuous_summary = c("mean_sd", "median_iqr", "mean_ci"),
  show_p = TRUE,
  show_smd = TRUE,
  show_missing = TRUE,
  weights = NULL,
  digits = 2L,
  apa = FALSE,
  output_format = "dataframe",
  title = "Table 1. Baseline Characteristics"
)

Arguments

data

Data frame.

group_col

Column defining groups, or NULL.

continuous_vars

Continuous variable names (auto-detect numeric non-group columns if NULL).

categorical_vars

Categorical names (auto-detect character / factor / logical if NULL).

continuous_summary

"mean_sd", "median_iqr" or "mean_ci".

show_p

Include p-value column.

show_smd

Include SMD column (2 groups only).

show_missing

Include missing count.

weights

Column name for survey weights or NULL.

digits

Decimal places.

apa

APA-style p-value formatting.

output_format

"dataframe", "latex", "html", "markdown", "text", "csv".

title

Table title.

Value

A vector of the computed values.

Examples

set.seed(1)
df <- data.frame(g = rep(c("a", "b"), 25), age = rnorm(50, 40, 10),
                 sex = sample(c("m", "f"), 50, TRUE))
res <- try(table1(df, group_col = "g", continuous_vars = "age",
                  categorical_vars = "sex"))
if (!inherits(res, "try-error")) head(res)
#>                           a            b p.value X.   SMD  Missing
#> N                        25           25                          
#> age, mean (SD) 41.96 (7.44) 40.05 (9.16)   0.686    0.229 0 (0.0%)
#> sex, n (%)                                 0.572          0 (0.0%)
#>   f              14 (56.0%)   11 (44.0%)                          
#>   m              11 (44.0%)   14 (56.0%)