add_n.tbl_summary: Add column with N

Description Usage Arguments Value Example Output Author(s) See Also Examples

View source: R/add_n.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## 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

Other tbl_summary tools: add_overall(), add_p.tbl_summary(), add_q(), add_stat_label(), bold_italicize_labels_levels, inline_text.tbl_summary(), inline_text.tbl_survfit(), modify, tbl_merge(), tbl_stack(), tbl_summary()

Other tbl_svysummary tools: add_overall(), add_p.tbl_svysummary(), add_q(), add_stat_label(), modify, tbl_merge(), tbl_stack(), tbl_svysummary()

Examples

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

ddsjoberg/gtsummary documentation built on April 8, 2021, 5:48 a.m.