Skip to contents

Creates a formatted frequency from count(able) data. Automatically tallies non-numeric data types (nrow or length) and supports vectorized data methods.

Usage

paste_freq(x, y, na.rm = TRUE, percent.sign = TRUE, digits = 1)

Arguments

x

A data.frame, numeric, or non-numeric. The numerator.

y

A data.frame, numeric, or non-numeric. The denominator. A single denominator may be used for multiple numerators or one denominator for each numerator.

na.rm

A logical. Whether to ignore NA's when tallying non-numeric data.

percent.sign

A logical. Indicates percent sign should be printed with frequencies.

digits

An integer. Number of digits to round to.

Value

A character vector of count(s) with frequencies.

Examples

# Numeric
paste_freq(20, 100)
#> [1] "20 (20%)"

# data.frame
df <- data.frame(x = c(1:100), y = TRUE)
paste_freq(df[1:20,], df)
#> [1] "20 (20%)"

# Mixed data types
paste_freq(20, df)
#> [1] "20 (20%)"

# Single denominator for multiple numerators
paste_freq(c(10,20,30), 100)
#> [1] "10 (10%)" "20 (20%)" "30 (30%)"