Learn R Programming

mosaicCore (version 0.9.4.0)

counts: 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 factor counts(x, ..., format = c("count", "proportion", "percent"))

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

# S3 method for 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

Run this code
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)
}

Run the code above in your browser using DataLab