ordinal_friendly {friendlynumber} | R Documentation |
Translate integer-ish numbers to an ordinal character vector
Description
Convert an integer vector, or numeric vector which is coercible to an integer without loss of precision, to an ordinal numeral (e.g. first, second, third).
ordinal_friendly_safe()
checks that all arguments are of the correct type
and raises an informative error otherwise. ordinal_friendly()
does not
perform input validation to maximize its speed.
Usage
ordinal_friendly(
numbers,
zero = "zeroth",
na = "missingth",
nan = "not a numberth",
inf = "infinitieth",
negative = "negative ",
and = FALSE,
hyphenate = TRUE
)
ordinal_friendly_safe(
numbers,
zero = "zeroth",
na = "missingth",
nan = "not a numberth",
inf = "infinitieth",
negative = "negative ",
and = FALSE,
hyphenate = TRUE
)
Arguments
numbers |
An integer or integer-ish numeric vector to translate. |
zero |
What to call values of |
na |
What to call values of |
nan |
What to call values of |
inf |
What to call values of |
negative |
A prefix added to the translation of negative elements of |
and |
Whether to insert an |
hyphenate |
Whether to hyphenate numbers 21 through 99 (e.g. |
Value
A non-NA character vector of the same length as numbers
.
Examples
ordinal_friendly(c(0, 1, 2, 3, NA, NaN, Inf, -Inf))
ordinal_friendly(10^10)
# Specify the translations of "special" numbers
ordinal_friendly(0, zero = "noneth")
# Modify the output formatting
ordinal_friendly(1234)
ordinal_friendly(1234, and = TRUE)
ordinal_friendly(1234, hyphenate = FALSE)
# Input validation
try(ordinal_friendly_safe(0.5))