Skip to contents

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.

Usage

num_sum(data, formula, digits = 3, na_rm = FALSE, caption = NULL)

Arguments

data

A data frame (or tibble).

formula

Variables to summarize given in formula notation: ~var1 or var1~var2. var1 should be numeric and var2, when supplied, should be a grouping variable.

digits

The number if digits to round to. Defaults to 3.

na_rm

Should missing values be removed? Defaults to FALSE.

caption

An override for the table caption. A sensible default is given.

Value

An object of class flextable. If in an interactive session, the table will be viewable immediately.

Examples

# not removing NAs is not recommended
num_sum(mtcars, ~wt)
#> Warning: Missing values *not* automatically removed from calculation. 
#>  You may get NA values in your output.
num_sum(mtcars, ~wt, na_rm = TRUE)
num_sum(mtcars, ~wt, na_rm = TRUE, digits = 2, caption = "This is a table")
num_sum(mtcars, wt~cyl, na_rm = TRUE)