Take numeric vectors of numerators, and demoninators, round them, format them with trailing zeros, and return as a character string along with the original numeric values.'

pretty_percentage(num, denom, digits = 2, percent_scaling = 100,
  as_per = TRUE, ...)

Arguments

num

A numeric or character vector coercible to a numeric vector. Empty character vectors will be returned by the function.

denom

A numeric vector

digits

Integer indicating the number of decimal places to be used.

percent_scaling

A numeric vector indicating the scaling used, by default this is 100 as this gives a percentage.

as_per

Logical indicating if the percentage should be deliminated by a % symbol.

...

Pass additional arguements to format.

Value

A character vector or string, with a percentage and the numerator and denominator used to calculate it

See also

pretty_round pretty_ci

Examples

## Return a percentage pretty_percentage(10, 500)
#> [1] "2.00% (10/500)"
## Return a vector of percentages pretty_percentage(c(1,4,6, 19), 100, digits = 1)
#> [1] "1.0% (1/100)" "4.0% (4/100)" "6.0% (6/100)" "19.0% (19/100)"
## Return a proportion pretty_percentage(c(1, 2, 4, 5, 2), c(100, 40, 50, 40, 30), as_per = FALSE)
#> [1] "1.00 (1/100)" "5.00 (2/40)" "8.00 (4/50)" "12.50 (5/40)" "6.67 (2/30)"