For each variable in a tbl_summary or tbl_likert table, add_n() adds
a column with the total number of non-missing (or missing) observations.
Usage
add_n(
x,
statistic = "{N_nonmiss}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)Arguments
- x
(
tbl_summary,tbl_likert)
A table created withtbl_summary()ortbl_likert().- statistic
(
string)
The statistic to report. Default is the number of non-missing observations for each variable,statistic = "{N_nonmiss}". The available statistics are:"{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.
Several statistics may be combined, e.g.
statistic = "{N_nonmiss} / {N_obs} ({p_nonmiss}%)". The short forms{N},{n},{n_miss}and{p}are accepted forN_obs,N_nonmiss,N_missandp_nonmiss.- col_label
(
string)
The column header. Default is"**N**".- footnote
(
scalar logical)
Whether to add a footnote naming the statistics shown. Default isFALSE.- last
(
scalar logical)
Whether to place the N column last in the table. Default isFALSE, which places it after the label column.- ...
Not used.
See also
Other add statistics:
add_ci(),
add_difference(),
add_difference_row(),
add_overall(),
add_p(),
add_p_continuous,
add_q(),
add_stat(),
add_stat_label(),
tests
Examples
# Example 1 ----------------------------------
trial |>
tbl_summary(by = trt, include = c(age, grade, response)) |>
add_n()
# Example 2 ----------------------------------
# show the number missing as well, with a footnote, as the last column
trial |>
tbl_summary(include = c(age, marker, response), missing = "no") |>
add_n(
statistic = "{N_nonmiss} / {N_obs} ({p_miss}% missing)",
col_label = "**N (missing)**",
footnote = TRUE,
last = TRUE
)