Skip to contents

Transform numeric values to percentage, by:

- Multiplying the values by 100, if sum = FALSE (default).
- Adding the values and computing the percentage, if sum = TRUE.

Usage

as_perc(x, sum = FALSE)

Arguments

x

A numeric vector

sum

A boolean value, if TRUE the function will add the values and compute the percentage (default = FALSE)

Value

A numeric vector with x as percentage.

Examples


#sum = FALSE (default)
x <- c(.4,.6)
as_perc(x)
#> [1] 40 60

#sum = TRUE
x <- c(120,180)
as_perc(x,sum = TRUE)
#> [1] 40 60