nth_friendly {friendlynumber} | R Documentation |
Translate integer-ish numbers to a character vector of nths (1st, 2nd, 3rd)
Description
Convert an integer vector, or numeric vector which is coercible to an integer without loss of precision, to an "nth" (e.g. 1st, 2nd, 3rd, 22nd, 1,000th).
nth_friendly_safe()
checks that all arguments are of the correct type
and raises an informative error otherwise. nth_friendly()
does not
perform input validation to maximize its speed.
Usage
nth_friendly(
numbers,
zero = "0th",
na = "missingth",
nan = "not a numberth",
inf = "infinitieth",
negative = "negative ",
bigmark = TRUE
)
nth_friendly_safe(
numbers,
zero = "zeroth",
na = "missingth",
nan = "not a numberth",
inf = "infinitieth",
negative = "negative ",
bigmark = 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 |
bigmark |
Whether the thousands places of formatted numbers should be separated with
a comma (e.g. |
Value
A non-NA character vector of the same length as numbers
.
Examples
nth_friendly(c(0, 1, 2, 3, 22, 1001, NA, NaN, Inf, -Inf))
# Specify the translations of "special" numbers
nth_friendly(c(1, 0, NA), zero = "noneth", na = "?")
# Use `bigmark` to add or remove commas
nth_friendly(1234, bigmark = TRUE)
nth_friendly(1234, bigmark = FALSE)
# Input validation
try(nth_friendly_safe(1234, bigmark = ","))