countr: Count formatter

View source: R/utils2.R

countrR Documentation

Count formatter

Description

Formats and prints a named vector of counts with percents.

Usage

countr(
  x,
  n,
  lowcase = NA,
  frac = FALSE,
  digits = 0L,
  which = seq_along(x),
  conf = NULL,
  show_conf = TRUE
)

Arguments

x

named vector of counts (a summary or table) or a long vector of character strings or factors

n

total number of observations; if not given, the length of x is used

lowcase

logical; names will be lowercase if TRUE, upper case if FALSE, and unchanged for any other value

frac

logical; if TRUE, counts are shown as fractions of n

digits

number of digits past the decimal point to keep

which

optional integer or character vector to select or re-order the output; note that this does not change the counts or percentages

conf, show_conf

optional arguments controlling binomial confidence intervals, passed to binconr

Examples

x <- setNames(3:1, c('Gold', 'Silver', 'Bronze'))
countr(x)
countr(x, conf = 0.95)
countr(x, n = 10, frac = TRUE)
countr(x, n = 10, frac = TRUE, which = 2)

## using a character/factor vector, not counts
countr(names(x))
countr(names(x), which = 1)
countr(names(x), which = c(3, 1), frac = TRUE)
countr(names(x), which = 'Silver', lowcase = TRUE)


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