Learn R Programming

cursory (version 1.0.0)

percent: Designate a numeric vector as a percent.

Description

The percentage is stored as a formatted string with the original value as an attribute. The formatted value is what will most often be needed but but allows for the original value to be recovered when the attribute is not stripped off.

Usage

percent(x, ...)

pct(x, places = attr(x, "places") %||% getOption("percent::places", 2), threshold = attr(x, "threshold") %||% getOption("percent::threshold", 1 * 10^-places), ...)

Arguments

x

a numeric object indicating a percentage.

...

additional formatting arguments.

places

Places to show after the decimal point.

threshold

The minimum absolute percentage to show.

Value

  • For pct() a string formatted for a percent.

  • For percent() the same as pct but is classed as a 'percent' and includes attributes for the raw value.

Functions

  • pct: Format a number as a percent.

Examples

Run this code
# NOT RUN {
pct(2/3)           #<-- no class
(x<- percent(2/3)) #<-- has class
as.numeric(x)
# }

Run the code above in your browser using DataLab