misc_br_num_formats: Miscellaneous Number Formatting Functions

Description Usage Arguments Value Author(s)

Description

Sometimes (for example when illustrating differences), it can be useful for positive numbers to be prefixed by a + sign, just as negative numbers are with a - sign. The following are a few (very simple) wrapper functions which do this.

fmt_pm

Is a wrapper for round, which also pastes a + sign before positive numbers

fmt_pc

A simple formatting function for percentages. Defaults to 0 decimal places

fmt_pc_pm

As above, but with a + prefix for positive numbers

format_nps

A very simple formatter for the Net Promoter Score

fmt_nps_pm

As above, but without the percentage sign

unsci

Unscientific notation: Short colloquial number formatting. For example, 1e+04 becomes "100k", 1.454e+09 becomes "1.5B", etc.

unsci_dollars

A convenience function for the above, with currency = TRUE as the default.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
fmt_pm(x, ...)

fmt_pc(x, type = c("round", "greater", "less"), digits = 0)

fmt_pc_pm(x, ...)

fmt_nps_pm(x, ...)

fmt_nps(x, ...)

unsci(x, digits = 1, currency = FALSE, symbol = "$", pad = TRUE)

unsci_dollars(x, ...)

Arguments

x

numeric data to format

...

Passed to round

type

The truncation function for the number, in the context of the text in which its likely to be formatted. One of round (the round function is used), greater (the floor function is used) or less (the ceiling function is used).

digits

Parameter passed to round

currency

Should numbers be prefixed with symbol?

symbol

if currency = TRUE, a string to prefix numbers with

pad

Should the resulting strings be prefix-padded with spaces to make all strings in the character vector a uniform width?

Value

character.

Author(s)

Brendan Rocks rocks.brendan@gmail.com


brendan-r/brocks documentation built on May 13, 2019, 5:08 a.m.