Title: | Number Names |
---|---|
Description: | Converts numeric vectors to character vectors of English number names. Provides conversion to cardinals, ordinals, numerators, and denominators. Supports negative and non-integer numbers. |
Authors: | Alexander Rossell Hayes [aut, cre, cph] , Eli Pousson [ctb] |
Maintainer: | Alexander Rossell Hayes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.1 |
Built: | 2024-10-30 04:00:22 UTC |
Source: | https://github.com/rossellhayes/nombre |
Convert numbers to adverbial character vectors (once, twice, three times)
adverbial(x, thrice = FALSE, ...) nom_adv(x, thrice = FALSE, ...) nom_times(x, thrice = FALSE, ...)
adverbial(x, thrice = FALSE, ...) nom_adv(x, thrice = FALSE, ...) nom_times(x, thrice = FALSE, ...)
x |
A numeric vector |
thrice |
A logical of length one.
If |
... |
Additional arguments passed to |
A character vector of the same length as x
Other number names:
cardinal()
,
collective()
,
denominator()
,
numerator()
,
ordinal()
,
ratio()
nom_adv(1:4) nom_adv(1:4, thrice = TRUE)
nom_adv(1:4) nom_adv(1:4, thrice = TRUE)
Convert numbers to cardinal character vectors (one, two, three)
cardinal(x, max_n = Inf, negative = "negative", ...) nom_card(x, max_n = Inf, negative = "negative", ...)
cardinal(x, max_n = Inf, negative = "negative", ...) nom_card(x, max_n = Inf, negative = "negative", ...)
x |
A numeric vector |
max_n |
A numeric vector.
When the absolute value of |
negative |
A character vector to append to negative numbers.
Defaults to |
... |
Arguments passed on to
|
A character vector of the same length as x
Decimal components of x
are automatically converted to fractions by
fracture::frac_mat()
.
uncardinal()
to convert character vectors to numbers
Other number names:
adverbial()
,
collective()
,
denominator()
,
numerator()
,
ordinal()
,
ratio()
nom_card(2) nom_card(1:10) nom_card(2 + 4/9) nom_card(-2) nom_card(-2, negative = "minus") nom_card(5:15, max_n = 10) paste("There are", nom_card(525600), "minutes in a year.") paste("There are", nom_card(3.72e13), "cells in the human body.") nom_card(1 / 2^(1:4)) nom_card(1 / 2^(1:4), common_denom = TRUE) nom_card(1 / 2^(1:4), base_10 = TRUE) nom_card(1 / 2^(1:4), base_10 = TRUE, common_denom = TRUE) nom_card(1 / 2:5) nom_card(1 / 2:5, base_10 = TRUE) nom_card(1 / 2:5, base_10 = TRUE, max_denom = 100)
nom_card(2) nom_card(1:10) nom_card(2 + 4/9) nom_card(-2) nom_card(-2, negative = "minus") nom_card(5:15, max_n = 10) paste("There are", nom_card(525600), "minutes in a year.") paste("There are", nom_card(3.72e13), "cells in the human body.") nom_card(1 / 2^(1:4)) nom_card(1 / 2^(1:4), common_denom = TRUE) nom_card(1 / 2^(1:4), base_10 = TRUE) nom_card(1 / 2^(1:4), base_10 = TRUE, common_denom = TRUE) nom_card(1 / 2:5) nom_card(1 / 2:5, base_10 = TRUE) nom_card(1 / 2:5, base_10 = TRUE, max_denom = 100)
Convert numbers to collective character vectors (the, both, all three)
collective(x, all_n = TRUE, of_the = FALSE, cardinal = TRUE, ...) nom_coll(x, all_n = TRUE, of_the = FALSE, cardinal = TRUE, ...)
collective(x, all_n = TRUE, of_the = FALSE, cardinal = TRUE, ...) nom_coll(x, all_n = TRUE, of_the = FALSE, cardinal = TRUE, ...)
x |
A numeric vector. |
all_n |
Whether to include the cardinal number after "all" for
collectives of 3 or more.
Defaults to |
of_the |
Whether to include "of the" for collectives other than 1.
Defaults to |
cardinal |
Whether to convert the number after "all" with |
... |
Additional arguments passed to |
A character vector of the same length as x
.
Other number names:
adverbial()
,
cardinal()
,
denominator()
,
numerator()
,
ordinal()
,
ratio()
paste(nom_coll(0:3), "fish") paste(nom_coll(9:12, max_n = 10), "fish")
paste(nom_coll(0:3), "fish") paste(nom_coll(9:12, max_n = 10), "fish")
Convert numbers to denominator character vectors (whole, half, third)
denominator(x, numerator = 1, quarter = TRUE, ...) nom_denom(x, numerator = 1, quarter = TRUE, ...)
denominator(x, numerator = 1, quarter = TRUE, ...) nom_denom(x, numerator = 1, quarter = TRUE, ...)
x |
A numeric vector |
numerator |
A numeric vector.
The numerator(s) associated with the denominator(s).
When |
quarter |
A logical of length one.
If |
... |
Additional arguments passed to |
A character vector of the same length as x
Other number names:
adverbial()
,
cardinal()
,
collective()
,
numerator()
,
ordinal()
,
ratio()
nom_denom(2) nom_denom(1:10) nom_denom(1:10, numerator = 2) nom_denom(1:10, numerator = 1:10) nom_denom(4) nom_denom(4, quarter = FALSE) nom_denom(1:10, numerator = 2, cardinal = FALSE) nom_denom(5:15, numerator = 2, max_n = 10)
nom_denom(2) nom_denom(1:10) nom_denom(1:10, numerator = 2) nom_denom(1:10, numerator = 1:10) nom_denom(4) nom_denom(4, quarter = FALSE) nom_denom(1:10, numerator = 2, cardinal = FALSE) nom_denom(5:15, numerator = 2, max_n = 10)
nom_numer()
and numerator()
are equivalent to nom_card()
and
cardinal()
for integers, but cardinals support fractional components
while numerator
s do not.
numerator(x, ...) nom_numer(x, ...)
numerator(x, ...) nom_numer(x, ...)
x |
A numeric vector |
... |
Additional arguments passed to |
Other number names:
adverbial()
,
cardinal()
,
collective()
,
denominator()
,
ordinal()
,
ratio()
Adds ordinal suffixes to numbers (or a character vector of number-like
words).
Converts numeric vectors to cardinal numbers before adding prefixes unless
cardinal
is FALSE
.
ordinal(x, cardinal = TRUE, ...) nom_ord(x, cardinal = TRUE, ...)
ordinal(x, cardinal = TRUE, ...) nom_ord(x, cardinal = TRUE, ...)
x |
A numeric or character vector. |
cardinal |
Whether to convert a numeric vector with |
... |
Further arguments passed to |
A character vector of the same length as x
Other number names:
adverbial()
,
cardinal()
,
collective()
,
denominator()
,
numerator()
,
ratio()
nom_ord(2) nom_ord(1:10) nom_ord(525600) nom_ord(1:10, cardinal = FALSE) nom_ord(5:15, max_n = 10) nom_ord(c("n", "dozen", "umpteen", "eleventy", "one zillion")) nom_ord(9 + 3/4)
nom_ord(2) nom_ord(1:10) nom_ord(525600) nom_ord(1:10, cardinal = FALSE) nom_ord(5:15, max_n = 10) nom_ord(c("n", "dozen", "umpteen", "eleventy", "one zillion")) nom_ord(9 + 3/4)
Convert numbers to ratio character vectors (two to one, one in three, five out of ten)
ratio(x, sep = "in", max_n = Inf, negative = "negative", ...) nom_ratio(x, sep = "in", max_n = Inf, negative = "negative", ...)
ratio(x, sep = "in", max_n = Inf, negative = "negative", ...) nom_ratio(x, sep = "in", max_n = Inf, negative = "negative", ...)
x |
A numeric vector |
sep |
A character vector separating components of the ratio.
Defaults to |
max_n |
A numeric vector.
When the absolute value of |
negative |
A character vector to append to negative numbers.
Defaults to |
... |
Arguments passed on to
|
x
is converted to a fraction by fracture::frac_mat()
.
A character vector of the same length as x
Other number names:
adverbial()
,
cardinal()
,
collective()
,
denominator()
,
numerator()
,
ordinal()
paste0("Our team is outnumbered ", nom_ratio(10), ".") paste0("The chances of winning are ", nom_ratio(1/1000000, sep = "in"), ".") nom_ratio(c(1, 10, 100)) nom_ratio(c(0, 0.5, 1.5)) nom_ratio(c(0, 0.125, 0.625, 1), sep = "out of", common_denom = TRUE) nom_ratio(5 / 10, sep = "in", base_10 = TRUE) nom_ratio(6 / 25, sep = "in") nom_ratio(6 / 25, sep = "out of", max_denom = 10)
paste0("Our team is outnumbered ", nom_ratio(10), ".") paste0("The chances of winning are ", nom_ratio(1/1000000, sep = "in"), ".") nom_ratio(c(1, 10, 100)) nom_ratio(c(0, 0.5, 1.5)) nom_ratio(c(0, 0.125, 0.625, 1), sep = "out of", common_denom = TRUE) nom_ratio(5 / 10, sep = "in", base_10 = TRUE) nom_ratio(6 / 25, sep = "in") nom_ratio(6 / 25, sep = "out of", max_denom = 10)
This function is in experimental development. It currently only supports English cardinal integers or character vectors produced by one of nombre's functions.
uncardinal(x) nom_uncard(x)
uncardinal(x) nom_uncard(x)
x |
A character vector of the cardinal names of numbers |
A numeric vector the same length as n
.
NAs will be produced for numbers with fractions or decimals or non-cardinal
numbers (e.g. ordinals).
cardinal()
to convert numeric vectors to number names
uncardinal("one") uncardinal("negative one hundred fifty-seven") uncardinal( c( "twenty-five", "one million two hundred thirty-four thousand five hundred sixty-seven" ) ) uncardinal("infinity") card <- cardinal(25) uncardinal(card) ord <- ordinal(25) uncardinal(ord)
uncardinal("one") uncardinal("negative one hundred fifty-seven") uncardinal( c( "twenty-five", "one million two hundred thirty-four thousand five hundred sixty-seven" ) ) uncardinal("infinity") card <- cardinal(25) uncardinal(card) ord <- ordinal(25) uncardinal(ord)