props: Compute all proportions or counts

Description Usage Arguments See Also Examples

View source: R/props-counts.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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 Jan. 16, 2021, 5:32 p.m.