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_nonmiss}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)
# S3 method for class 'tbl_svysummary'
add_n(
x,
statistic = "{N_nonmiss}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)
# S3 method for class 'tbl_likert'
add_n(
x,
statistic = "{N_nonmiss}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)
Arguments
- x
(
tbl_summary
)
Object with class'tbl_summary'
created withtbl_summary()
function.- statistic
(
string
)
String indicating the statistic to report. Default is the number of non-missing observation for each variable,statistic = "{N_nonmiss}"
. All statistics available to report include:"{N_obs}"
total number of observations,"{N_nonmiss}"
number of non-missing observations,"{N_miss}"
number of missing observations,"{p_nonmiss}"
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_nonmiss} / {N_obs} ({p_nonmiss}%)"
- col_label
(
string
)
String indicating the column label. Default is"**N**"
- footnote
(scalar
logical
)
Logical argument indicating whether to print a footnote clarifying the statistics presented. Default isFALSE
- last
(scalar
logical
)
Logical indicator to include N column last in table. Default isFALSE
, which will display N column first.- ...
These dots are for future extensions and must be empty.
Examples
# Example 1 ----------------------------------
trial |>
tbl_summary(by = trt, include = c(trt, age, grade, response)) |>
add_n()
Characteristic
N
Drug A
N = 981
Drug B
N = 1021
1 Median (Q1, Q3); n (%)
# Example 2 ----------------------------------
survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
tbl_svysummary(by = Survived, percent = "row", include = c(Class, Age)) |>
add_n()
Characteristic
N
No
N = 1,4901
Yes
N = 7111
1 n (%)