Skip to contents

This function converts a numeric vector's values into their abbreviated character equivalent, i.e. 100E6 into 100M and viceversa.

Usage

num_abbr(x, n = 3, numeric = FALSE, ...)

Arguments

x

Numeric vector

n

Integer. Single numeric value, specifying number of significant figures to show. Range 1 to 6.

numeric

Boolean. Transform abbreviated number into numeric?

...

Additional parameters.

Value

Vector of character or numeric values that contain converted values

Examples

num_abbr(rnorm(10) * 1e6)
#>  [1] "-560K"  "-230K"  "1.56M"  "70.5K"  "129K"   "1.72M"  "461K"   "-1.27M"
#>  [9] "-687K"  "-446K" 
num_abbr(rnorm(10) * 1e6, n = 1)
#>  [1] "1M"    "400K"  "400K"  "100K"  "-600K" "2M"    "500K"  "-2M"   "700K" 
#> [10] "-500K"
num_abbr(c("3K", "-58.3M", NA, 1), numeric = TRUE)
#> [1]      3000 -58300000        NA         1