R/ratio.R
ratio.RdConvert 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", ...)A numeric vector
A character vector separating components of the ratio.
Defaults to "in".
A numeric vector.
When the absolute value of x is greater than max_n, x remains
numeric instead of being converted to words.
If max_n is negative, no xs will be converted to words.
(This can be useful when max_n is passed by another function.)
Defaults to Inf, which converts all xs to words.
A character vector to append to negative numbers.
Defaults to "negative".
Arguments passed on to fracture::frac_mat
denomIf denom is not NULL, all fractions will have a
denominator of denom. This will ignore all other arguments that affect
the denominator.
base_10If TRUE, all denominators will be a power of 10.
common_denomIf TRUE, all fractions will have the same denominator.
If the least common denominator is greater than max_denom,
max_denom is used.
max_denomAll denominators will be less than or equal to
max_denom.
If base_10 is TRUE, the maximum denominator will be the largest power
of 10 less than max_denom.
A max_denom greater than the inverse square root of
machine double epsilon will produce a warning because floating
point rounding errors can occur when denominators grow too large.
A character vector of the same length as x
x is converted to a fraction by fracture::frac_mat().
Other number names:
adverbial(),
cardinal(),
collective(),
denominator(),
numerator(),
ordinal()
paste0("Our team is outnumbered ", nom_ratio(10), ".")
#> [1] "Our team is outnumbered ten in one."
paste0("The chances of winning are ", nom_ratio(1/1000000, sep = "in"), ".")
#> [1] "The chances of winning are one in one million."
nom_ratio(c(1, 10, 100))
#> [1] "one in one" "ten in one" "one hundred in one"
nom_ratio(c(0, 0.5, 1.5))
#> [1] "zero in one" "one in two" "three in two"
nom_ratio(c(0, 0.125, 0.625, 1), sep = "out of", common_denom = TRUE)
#> [1] "zero out of eight" "one out of eight" "five out of eight"
#> [4] "eight out of eight"
nom_ratio(5 / 10, sep = "in", base_10 = TRUE)
#> [1] "five in ten"
nom_ratio(6 / 25, sep = "in")
#> [1] "six in twenty-five"
nom_ratio(6 / 25, sep = "out of", max_denom = 10)
#> [1] "one out of four"