numbers2prefix: Format numbers using SI unit prefixes

View source: R/numeric.R

numbers2prefixR Documentation

Format numbers using SI unit prefixes

Description

Using SI unit prefixes is a more compact way to write very large or very small numbers which can sometimes be useful. This function takes a number (or a vector of numbers) and returns the equivalent value expressed using the nearest prefix. My thanks to https://stackoverflow.com/users/843265/tomelgin for posting the code that this function was based on (see first link below).

Usage

numbers2prefix(number, rounding = FALSE, digits = ifelse(rounding, NA, 6))

Arguments

number

number, numeric vector

rounding

rounds number to nearest integer (default FALSE), boolean

digits

if rounding=FALSE, lets you specify significant figures (default 6), numeric

Value

number followed by SI prefix (as character string, separated by narrow no-break space)

See Also

https://stackoverflow.com/questions/11340444/convert-numbers-to-si-prefix

https://stackoverflow.com/questions/28159936/format-numbers-with-million-m-and-billion-b-suffixes

https://www.nist.gov/pml/owm/metric-si-prefixes


chepec/R-common documentation built on July 27, 2023, 11:33 a.m.