tbl_gtsummary: Summarise Table as 'gtsummary'

View source: R/data.frame.R

tbl_gtsummaryR Documentation

Summarise Table as gtsummary

Description

Summarise a data.frame as gtsummary with Dutch defaults. These objects are based on the gt package by RStudio. To provide Certe style and compatibility with MS Word, use tbl_flextable() to transform the gtsummary object.

Usage

tbl_gtsummary(
  x,
  by = NULL,
  label = NULL,
  digits = 1,
  ...,
  language = "nl",
  column1_name = "Eigenschap",
  add_n = FALSE,
  add_p = FALSE,
  add_ci = FALSE,
  add_overall = FALSE,
  decimal.mark = dec_mark(),
  big.mark = big_mark()
)

Arguments

x

a data.frame

by

(tidy-select)
A single column from data. Summary statistics will be stratified by this variable. Default is NULL.

label

(formula-list-selector)
Used to override default labels in summary table, e.g. list(age = "Age, years"). The default for each variable is the column label attribute, attr(., 'label'). If no label has been set, the column name is used.

digits

(formula-list-selector)
Specifies how summary statistics are rounded. Values may be either integer(s) or function(s). If not specified, default formatting is assigned via assign_summary_digits(). See below for details.

...

Arguments passed on to gtsummary::tbl_summary()

language

the language to use, defaults to Dutch

column1_name

name to use for the first column

add_n

add the overall N using gtsummary::add_n()

add_p

add the p values gtsummary::add_p() (tests will be determined automatcally)

add_ci

add the confidence interval using gtsummary::add_ci()

add_overall

add the overall statistics using gtsummary::add_overall()

decimal.mark

decimal separator, defaults to dec_mark()

big.mark

thousands separator, defaults to big_mark()

Details

tbl_gtsummary() creates a summary table with gtsummary::tbl_summary(), to which different extra columns can be added e.g. with add_p = TRUE and add_overall = TRUE.

Examples

# These examples default to the Dutch language

iris |>
  tbl_gtsummary()

iris |> 
  tbl_gtsummary(Species, add_p = TRUE)
  
iris |> 
  tbl_gtsummary(Species, add_n = TRUE)
  
# support strata by providing 
iris2 <- iris
iris2$Category <- sample(LETTERS[1:2], size = 150, replace = TRUE)
head(iris2)

iris2 |> 
  tbl_gtsummary(c(Category, Species))

# transform to flextable 
# (formats to Certe style and allows rendering to Word)
iris |> 
  tbl_gtsummary(Species) |> 
  tbl_flextable()

certe-medical-epidemiology/certetoolbox documentation built on April 17, 2025, 3:24 a.m.