Learn R Programming

qwraps2 (version 0.1.1)

n_perc: Count and Percentage

Description

A function for calculating and formatting counts and percentages.

Usage

n_perc(x, digits = getOption("qwraps2_frmt_digits", 2), na_rm = FALSE,
  show_denom = "ifNA", markup = getOption("qwraps2_markup", "latex"))

Arguments

x
a 0:1 or boolean vector
digits
digits to the right of the decimal point to return in the percentage estimate.
na_rm
if true, omit NA values
show_denom
defaults to "ifNA". Other options are "always" or "never".
markup
latex or markdown

Value

  • a character vector of the formatted values

Details

Default behavior will return the count of successes and the percentage as "N (ppcan be controlled by setting na.rm = TRUE. In this case, the number of non-missing values will be reported by default. Omission of the non-missing values can be controlled by setting show_denom = "never".

Examples

Run this code
n_perc(c(0, 1,1, 1, 0, 0), show_denom = "always")
n_perc(c(0, 1,1, 1, 0, 0, NA), na_rm = TRUE)

n_perc(mtcars$cyl == 6)

set.seed(42)
x <- rbinom(4269, 1, 0.314)
n_perc(x)
n_perc(x, show_denom = "always")

Run the code above in your browser using DataLab