counts | R Documentation |
Compute vector of counts, proportions, or percents for each unique value (and NA
if there
is missing data) in a vector.
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")
x |
A vector or a formula. |
... |
Arguments passed to methods. |
format |
One of |
data |
A data frame. |
mosaic::prop()
mosaic::count()
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.