tbl_num_sum()
is a wrapper around mosaic::favstats()
and creates a tidy table of summary statistics
including the min, q1, median, q3, max, mean, standard deviation, n, and missing values.
Arguments
- data
A data frame (or tibble).
- formula
Variables to summarize given in formula notation:
~var1
orvar1~var2
.var1
should be numeric andvar2
, when supplied, should be a grouping variable.- digits
The number of digits to round to. Defaults to 3.
- caption
An override for the table caption. A sensible default is given.
- na_rm
Should missing values be removed? Defaults to TRUE.
Value
An object of class flextable. If in an interactive session, the table will be viewable immediately.
Examples
tbl_num_sum(mtcars, ~wt)
tbl_num_sum(mtcars, ~wt)
tbl_num_sum(mtcars, ~wt, digits = 2, caption = "This is a table")
tbl_num_sum(mtcars, wt~cyl)
# not removing NAs is an option but not recommended
tbl_num_sum(airquality, ~Ozone, na_rm = FALSE)
#> ! NAs were detected but not removed. You may get missing values in your output.
tbl_num_sum(airquality, Ozone~Month, na_rm = FALSE)
#> ! NAs were detected but not removed. You may get missing values in your output.