num2char: Numeric to character string

View source: R/utils2.R

num2charR Documentation

Numeric to character string

Description

Convert a number to its word equivalent.

Usage

num2char(x, informal = FALSE, cap = TRUE)

Arguments

x

an integer to convert to words; can be negative or positive but decimals will be rounded first

informal

logical; if TRUE, adds "and" before tens or ones

cap

logical; if TRUE, capitalizes the first word

Details

Whole numbers twenty-one through ninety-nine are hyphenated when they are written out whether used alone or as part of a larger number; for example: "twenty-one" or "one million twenty-one."

Whole numbers in this range are not hyphenated for other orders of magnitude; for example, 52,052 is written "fifty two thousand fifty- two" and not "fifty-two thousand fifty-two." This rule applies only to two-word numbers 21-99.

Informal and formal case differ only by the use of "and" to separate 1-99: "one hundred one" is the formal case, and "one hundred and one" is the informal case.

References

http://dictionary.reference.com/help/faq/language/g80.html

https://www.grammarbook.com/numbers/numbers.asp

See Also

case; adapted from github.com/ateucher/useful_code/blob/master/R/numbers2words.r

Examples

num2char(52052, TRUE)
num2char(52052, FALSE)

## vectorized
num2char(-1:2)

x <- c(-1000, 100, 52052, 3922, 3012, 201, -152, 1002, 91070432)
cbind(x, informal = num2char(x, TRUE), formal = num2char(x, FALSE))


raredd/rawr documentation built on May 19, 2024, 1:02 p.m.