fmt_pct_special: Format Numerical Values to Special Percentage Strings

View source: R/fmt_pct_special.R

fmt_pct_specialR Documentation

Format Numerical Values to Special Percentage Strings

Description

This function formats numeric vectors with values between 0 and 1 into percentage strings with special specifications. Those specifications are:

  • 0 and 1 are converted to "0%" and "100%" respectively (takes machine precision into account)

  • all other values < 0.01 are converted to "<1%"

  • all other values between 0.01 and 0.995 are rounded to percentages without decimals

  • values between 0.995 and 0.999 are rounded to percentages with 1 decimal

  • values between 0.999 and 1 are converted to ">99.9%" unless closer to 1 than machine precision.

Usage

fmt_pct_special(x)

Arguments

x

A vector of numerical values

Value

A character vector

Examples

x <- c(0, 0.004, 0.009, 0.011, 0.9, 0.98, 0.994,
       .995, .9989, .999, .9991, .99999999)
fmt <- fmt_pct_special(x)
data.frame(x = x, fmt = fmt)

nflseedR documentation built on April 4, 2025, 2:08 a.m.