Learn R Programming

mosaic (version 0.13.0)

tally: Tabulate categorical data

Description

Tabulate categorical data

Usage

tally(x, ...)

tally_internal(x, ...)

## S3 method for class 'tbl': tally_internal(x, wt, sort = FALSE, ..., envir = parent.frame())

## S3 method for class 'data.frame': tally_internal(x, wt, sort = FALSE, ..., envir = parent.frame())

## S3 method for class 'formula': tally_internal(x, data = parent.frame(2), format = c("count", "proportion", "percent", "data.frame", "sparse", "default"), margins = FALSE, quiet = TRUE, subset, useNA = "ifany", ...)

Arguments

x
an object
...
additional arguments passed to table
wt
for weighted tallying, see tally in dplyr
sort
a logical, see tally in dplyr
envir
an environment in which to evaluate
data
a data frame or environment in which evaluation occurs. Note that the default is data=parent.frame(). This makes it convenient to use this function interactively by treating the working envionment as if it were a data frame. But this may n
format
a character string describing the desired format of the results. One of 'default', 'count', 'proportion', 'percent', 'data.frame', 'sparse', or 'default'. In case
margins
a logical indicating whether marginal distributions should be displayed.
quiet
a logical indicating whether messages about order in which marginal distributions are calculated should be surpressed. See addmargins.
subset
an expression evaluating to a logical vector used to select a subset of data
useNA
as in table, but the default here is "ifany".

Details

The dplyr package also exports a tally function. If x inherits from class "tbl", then dplyr's tally is called. This makes it easier to have the two package coexist.

Examples

Run this code
if (require(mosaicData)) {
tally( ~ substance, data=HELPrct)
tally( ~ substance & sex , data=HELPrct)
tally( sex ~ substance, data=HELPrct)   # equivalent to tally( ~ sex | substance, ... )
tally( ~ substance | sex , data=HELPrct)
tally( ~ substance | sex , data=HELPrct, format='count')
tally( ~ substance & sex , data=HELPrct, format='percent')
# force NAs to show up
tally( ~ sex, data=HELPrct, useNA="always")
# show NAs if any are there
tally( ~ link, data=HELPrct)
# ignore the NAs
tally( ~ link, data=HELPrct, useNA="no")
}

Run the code above in your browser using DataLab