pctr-deprecated: Format proportion (0 < p < 1) to a percent (0 < pct < 100)

pctr-deprecatedR Documentation

Format proportion (0 < p < 1) to a percent (0 < pct < 100)

Description

Given a proportion (0 < p < 1), the function converts it to a percent (0 < pct < 100) as either a numeric (when as_text = FALSE) or as a string with a percent sign (as_text = TRUE). I owe this one to my buddy Kyle Hart. scales::percent() has always been my preferred way to format percents but this function has a little more flexibility and the number of decimal places can be specified.

Usage

pctr(x, d, as_text, latex)

Arguments

x

A numeric vector.

d

integer indicating the number of decimal places (round).

as_text

logical; if FALSE, a numeric value is returned; if TRUE, then a character is returned with a percent symbol

latex

logical; default is FALSE. If TRUE, then the percent symbol is escaped.

Value

An object of similar structure to x

See Also

lamisc-deprecated

Examples

pctr(x = runif(10), d = 1)
pctr(x = runif(10), d = 1, latex = TRUE)
pctr(x = runif(10), d = 1, as_text = FALSE)


emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.