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
# S3 method for tbl_summary
add_n(
x,
statistic = "{n}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)# S3 method for tbl_svysummary
add_n(
x,
statistic = "{n}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)
A tbl_summary
or tbl_svysummary
object
Object with class tbl_summary
from the tbl_summary function or
with class tbl_svysummary
from the tbl_svysummary function
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_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
survey summaries also have the following unweighted statistics available:
"N_obs_unweighted"
, "N_miss_unweighted"
, "N_nonmiss_unweighted"
, "p_miss_unweighted"
, "p_nonmiss_unweighted"
The argument uses glue::glue syntax and multiple statistics may be reported,
e.g. statistic = "{N_nonmiss} / {N_obs} ({p_nonmiss}%)"
String indicating the column label. Default is "**N**"
Logical argument indicating whether to print a footnote
clarifying the statistics presented. Default is FALSE
Logical indicator to include N column last in table.
Default is FALSE
, which will display N column first.
Not used
Example 1
Daniel D. Sjoberg
Review list, formula, and selector syntax used throughout gtsummary
Other tbl_summary tools:
add_ci()
,
add_overall()
,
add_p.tbl_summary()
,
add_q()
,
add_stat_label()
,
bold_italicize_labels_levels
,
inline_text.tbl_summary()
,
inline_text.tbl_survfit()
,
modify
,
separate_p_footnotes()
,
tbl_custom_summary()
,
tbl_merge()
,
tbl_split()
,
tbl_stack()
,
tbl_strata()
,
tbl_summary()
Other tbl_svysummary tools:
add_overall()
,
add_p.tbl_svysummary()
,
add_q()
,
add_stat_label()
,
modify
,
separate_p_footnotes()
,
tbl_merge()
,
tbl_split()
,
tbl_stack()
,
tbl_strata()
,
tbl_svysummary()
# Example 1 ----------------------------------
tbl_n_ex <-
trial[c("trt", "age", "grade", "response")] %>%
tbl_summary(by = trt) %>%
add_n()
Run the code above in your browser using DataLab