as.percent: Format Numbers as Percentages

as.percentR Documentation

Format Numbers as Percentages

Description

Format numeric values as character strings with (optional) trailing percent sign.

Usage

as.percent(x, digits = 2, big.value = 1, percentSign = TRUE, sep = " ")

Arguments

x

vector of numeric values, typically in the range 0..'big.value'

digits

desired number of significant digits after the decimal point

big.value

largest expected value. All values get scaled so that 'big.value' would be returned as '100 %'

percentSign

logical, should the trailing percent sign be appended

sep

character string to insert between the numeric percentage and the percent sign.

Details

Used to represent arbitrary values as a percentage in character format, where the value to be represented as 100 % is given as 'big.value'. Implemented via 'formatC'.

Value

A character vector of the same length as 'x', scaled such that 'big.value' equals 100, with 'digits' significant digits and a trailing ' %' appended.

Examples

  as.percent( c( 7,21, 4), big.value=30, digits=2)

robertdouglasmorrison/DuffyTools documentation built on Sept. 13, 2024, 4:51 p.m.