Skip to contents

tbl_pctile() is a wrapper around mosaic::quantile() and creates a tidy table of data values at the given percentiles.

Usage

tbl_pctile(
  data,
  formula,
  digits = 3,
  probs = c(0, 0.25, 0.5, 0.75, 1),
  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 of digits to round to. Defaults to 3.

probs

A vector of percentiles to compute. Each value must be between 0 and 1, inclusive. Defaults to 0, 25%, 50%, 75%, and 100%.

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

tbl_pctile(mtcars, ~wt)
tbl_pctile(mtcars, ~wt, probs = c(.17, .3, .5, .7, .9, 1))
tbl_pctile(mtcars, wt~cyl, digits = 4)
tbl_pctile(airquality, ~Solar.R) #> Note: NAs always removed for percentile tables #> This message is displayed once per session.
tbl_pctile(airquality, Month~Solar.R)
try(tbl_pctile(mtcars, ~wt, probs = c(25, 50, 75, 100))) #> Error in tbl_pctile(mtcars, ~wt, probs = c(25, 50, 75, 100)) : #> You seem to have entered an invalid entry to the `probs` argument. These #> values should be between 0 and 1 (inclusive).