A function to calculate and format a quantile range.
Usage
fmt_quantile_range(
x,
format = "%.1f",
sep = "-",
lower = 0.25,
upper = 0.75,
type = 7
)
Value
The formatted quantile range.
Arguments
x
The input data vector or data frame column.
format
A formatting string suitable for input into the
sprintf function. By default, this format is
defined as "%.1f", which displays the value with one decimal place.
sep
The character to use as a separator between the two quantiles.
lower
The lower quantile range. Default is .25.
upper
The upper quantile range. Default is .75.
type
An integer between 1 and 9 selecting one of the nine quantile
algorithms. The default is 7, which is the standard R default.
If you are trying to match SAS results, use type 2.
See the quantile function documentation for further details.
Details
This function calculates a quantile range using the stats package
quantile
function, and then formats the output using sprintf.
You may control the format using the format parameter. Function will
ignore any NA values in the input data. Results are returned as a
character vector.
By default, the function calculates the 1st and 3rd quantiles at .25 and .75.
The upper and lower quantile ranges may be changed with the upper
and lower parameters.
See Also
Other helpers:
fmt_cnt_pct(),
fmt_mean_sd(),
fmt_median(),
fmt_n(),
fmt_range()