big_number: Abbreviate large numbers by order of magnitude

Description Usage Arguments Details Value Examples

View source: R/big_number.R

Description

This picks out the order of magnitude of each number in a vector and returns a formatted abbreviation, such as 1230 –> 1.2k. It handles abbreviations through the trillions; after that, it's suggested that you switch over to scientific notation. The convenience of this function over those from the scales package is that you can mix & match orders of magnitude.

Usage

1
2
3
big_number(x, digits = 2)

big_money(x, digits = 2, currency = "$")

Arguments

x

A numeric vector

digits

Number of digits (significant figures) to keep; defaults to 2

currency

Symbol to use to denote currency; defaults "$"

Details

Its sibling big_money tacks on a currency symbol, placed after a negative sign if applicable.

Value

A character vector

Examples

1
2
3
4
5
6
big_number(c(123, 12345, 1234567), digits = 3)
big_number(c(-12000, 15000, 16000, 77777))
big_money(c(-12000, 15000, 16000, 2e6))

# take care with your significant digits choices
purrr::map_chr(1:3, ~big_number(987, digits = .))

camille-s/camiller documentation built on Jan. 22, 2022, 6:50 a.m.