Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

add_n.tbl_summary

Add column with N


Description

For each variable in a tbl_summary table, the add_n function adds a column with the total number of non-missing (or missing) observations

Usage

## S3 method for class 'tbl_summary'
add_n(
  x,
  statistic = "{n}",
  col_label = "**N**",
  footnote = FALSE,
  last = FALSE,
  missing = NULL,
  ...
)

## S3 method for class 'tbl_svysummary'
add_n(
  x,
  statistic = "{n}",
  col_label = "**N**",
  footnote = FALSE,
  last = FALSE,
  missing = NULL,
  ...
)

Arguments

x

Object with class tbl_summary from the tbl_summary function or with class tbl_svysummary from the tbl_svysummary function

statistic

String indicating the statistic to report. Default is the number of non-missing observation for each variable, statistic = "{n}". Other statistics available to report include:

  • "{N}" total number of observations,

  • "{n}" number of non-missing observations,

  • "{n_miss}" number of missing observations,

  • "{p}" percent non-missing data,

  • "{p_miss}" percent missing data The argument uses glue::glue syntax and multiple statistics may be reported, e.g. statistic = "{n} / {N} ({p}%)"

col_label

String indicating the column label. Default is "**N**"

footnote

Logical argument indicating whether to print a footnote clarifying the statistics presented. Default is FALSE

last

Logical indicator to include N column last in table. Default is FALSE, which will display N column first.

missing

DEPRECATED. Logical argument indicating whether to print N (missing = FALSE), or N missing (missing = TRUE). Default is FALSE

...

Not used

Value

A tbl_summary or tbl_svysummary object

Example Output

Example 1

Author(s)

Daniel D. Sjoberg

See Also

Examples

# Example 1 ----------------------------------
tbl_n_ex <-
  trial[c("trt", "age", "grade", "response")] %>%
  tbl_summary(by = trt) %>%
  add_n()

gtsummary

Presentation-Ready Data Summary and Analytic Result Tables

v1.4.0
MIT + file LICENSE
Authors
Daniel D. Sjoberg [aut, cre] (<https://orcid.org/0000-0003-0862-2018>), Michael Curry [aut] (<https://orcid.org/0000-0002-0261-4044>), Margie Hannum [aut] (<https://orcid.org/0000-0002-2953-0449>), Joseph Larmarange [aut] (<https://orcid.org/0000-0001-7097-700X>), Karissa Whiting [aut] (<https://orcid.org/0000-0002-4683-1868>), Emily C. Zabor [aut] (<https://orcid.org/0000-0002-1402-4498>), Esther Drill [ctb] (<https://orcid.org/0000-0002-3315-4538>), Jessica Flynn [ctb] (<https://orcid.org/0000-0001-8310-6684>), Jessica Lavery [ctb] (<https://orcid.org/0000-0002-2746-5647>), Stephanie Lobaugh [ctb], Gustavo Zapata Wainberg [ctb] (<https://orcid.org/0000-0002-2524-3637>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.