A function for calculating and formatting the median and inner quartile range of a data vector.
Details
Given a numeric vector, median_iqr
will return a character string with
the median and IQR. Formatting of the output will be extended in
future versions.
Examples
set.seed(42)
x <- rnorm(1000, 3, 4)
median(x)
#> [1] 2.947463
quantile(x, probs = c(1, 3)/4)
#> 25% 75%
#> 0.298158 5.656021
median_iqr(x)
#> [1] "2.95 (0.30, 5.66)"
median_iqr(x, show_n = "always")
#> [1] "1,000; 2.95 (0.30, 5.66)"
x[187] <- NA
# median_iqr(x) ## Will error
median_iqr(x, na_rm = TRUE)
#> [1] "999; 2.95 (0.28, 5.65)"