# percentage: Transform to percentage In cleaner: Fast and Easy Data Cleaning

## Description

Transform input to a percentage. The actual values are numeric, but will be printed as formatted percentages.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11``` ```as.percentage(x, ...) is.percentage(x) ## S3 method for class 'percentage' print(x, ...) ## S3 method for class 'percentage' format(x, digits = NULL, ...) percentage(x, digits = NULL, ...) ```

## Arguments

 `x` input `...` other parameters passed on to methods `digits` how many digits should be printed. It defaults to printing all decimals available in the data after transforming to a percentage, with a minimum of 0 and a maximum of 3.

## Details

Printing percentages will always have a percentage symbol and is never written in scientific format (like 2.5e+04%).

The function `percentage` is a wrapper around `format(as.percentage(...))` with automatic determination of the number of digits, varying between 0 and 1. It also, unlike R, rounds according to basic math rules: `percentage(0.4455)` returns `"44.6%"` and not `"44.5%"`. This function always returns a character, and can also be used in plotting, see Examples.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```proportion <- as.percentage(c(0.25, 2.5, 0.0025)) proportion sum(proportion) max(proportion) mean(proportion) as.percentage(2.5e-14) as.percentage(pi) format(as.percentage(pi)) format(as.percentage(pi), digits = 6) round(0.4455 * 100, 1) # mind the rounding percentage(0.4455) # does not round to 44.5% ```

cleaner documentation built on June 13, 2021, 5:06 p.m.