props: Compute all proportions or counts

View source: R/props-counts.R

countsR Documentation

Compute all proportions or counts

Description

Compute vector of counts, proportions, or percents for each unique value (and NA if there is missing data) in a vector.

Usage

counts(x, ...)

## S3 method for class 'factor'
counts(x, ..., format = c("count", "proportion", "percent"))

## Default S3 method:
counts(x, ..., format = c("count", "proportion", "percent"))

## S3 method for class 'formula'
counts(x, data, ..., format = "count")

props(x, ..., format = "proportion")

percs(x, ..., format = "percent")

Arguments

x

A vector or a formula.

...

Arguments passed to methods.

format

One of "count", "proportion", or "percent". May be abbreviated.

data

A data frame.

See Also

mosaic::prop()

mosaic::count()

Examples

if (require(mosaicData)) {
  props(HELPrct$substance)
  # numeric version tallies missing values as well
  props(HELPmiss$link)
  # Formula version omits missing data with warning (by default)
  props( ~ link, data = HELPmiss)                       # omit NAs with warning
  props( ~ link, data = HELPmiss, na.action = na.pass)  # no warning; tally NAs
  props( ~ link, data = HELPmiss, na.action = na.omit)  # no warning, omit NAs
  props( ~ substance | sex, data = HELPrct)
  props( ~ substance | sex, data = HELPrct, format = "percent")
  percs( ~ substance | sex, data = HELPrct)
  counts( ~ substance | sex, data = HELPrct)
  df_stats( ~ substance | sex, data = HELPrct, props, counts)
  df_stats( ~ substance | sex, data = HELPmiss, props, na.action = na.pass)
}


mosaicCore documentation built on Nov. 5, 2023, 9:06 a.m.