intr: Interval formatter

View source: R/utils2.R

intrR Documentation

Interval formatter

Description

Calculate summary statistic with range or confidence interval.

Usage

intr(..., fun = median, conf = NULL, digits = 0L, na.rm = FALSE)

intr2(
  ...,
  fun = median,
  na.rm = FALSE,
  digits = 0L,
  conf.int = 0.95,
  range = TRUE,
  ci = FALSE,
  sd = FALSE,
  mad = FALSE,
  iqr = FALSE
)

Arguments

...

numeric vector or string of numeric vectors

fun

summary stat function, usually mean or median

conf

width of confidence interval in [0,1]; if NULL (default), returns min and max of ...

digits

number of digits (includes trailing 0s)

na.rm

logical; if TRUE, any NA and NaN are removed from ... before FUN and quantile are computed

conf.int

for intr2, the confidence level if conf = TRUE; default is 0.95

range, ci, sd, mad, iqr

logical; for intr2 if TRUE, the range (default), confidence interval, standard deviation, median absolute deviation, and/or inner quartile range are shown

See Also

roundr

Examples

x <- 1:10
intr(x)
intr(x, conf = 0.95)

## inner quartile range
cbind(
  'median (IQR)' = lapply(mtcars, intr, conf = 0.5, digits = 2),
  'mean (range)' = lapply(mtcars, intr, fun = mean, digits = 2)
)

## compare to
summary(mtcars)

x <- mtcars$mpg
intr2(x)
intr2(x, fun = mean, sd = TRUE, ci = TRUE, conf.int = 0.9)

## compare
x <- list(mtcars$mpg, mtcars$wt)
intr2(x, range = TRUE, iqr = TRUE, digits = 2)
summary(mtcars[, c('mpg', 'wt')])


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.