vec_fmt_spelled_num | R Documentation |
With numeric values in a vector, we can transform those to numbers that are
spelled out. Any values from 0
to 100
can be spelled out according to the
specified locale. For example, the value 23
will be rendered as
"twenty-three"
if the locale is an English-language one (or, not provided
at all); should a Swedish locale be provided (e.g., "sv"
), the output will
instead be "tjugotre"
.
vec_fmt_spelled_num(
x,
pattern = "{x}",
locale = NULL,
output = c("auto", "plain", "html", "latex", "rtf", "word")
)
x |
The input vector
This is the input vector that will undergo transformation to a character vector of the same length. Values within the vector will be formatted. |
pattern |
Specification of the formatting pattern
A formatting pattern that allows for decoration of the formatted value. The
formatted value is represented by the |
locale |
Locale identifier
An optional locale identifier that can be used for formatting values
according to the locale's rules. Examples include |
output |
Output format
The output style of the resulting character vector. This can either be
|
A character vector.
The following 80 locales are supported in the locale
argument of
vec_fmt_spelled_num()
: "af"
(Afrikaans), "ak"
(Akan), "am"
(Amharic),
"ar"
(Arabic), "az"
(Azerbaijani), "be"
(Belarusian), "bg"
(Bulgarian), "bs"
(Bosnian), "ca"
(Catalan), "ccp"
(Chakma), "chr"
(Cherokee), "cs"
(Czech), "cy"
(Welsh), "da"
(Danish), "de"
(German),
"de-CH"
(German (Switzerland)), "ee"
(Ewe), "el"
(Greek), "en"
(English), "eo"
(Esperanto), "es"
(Spanish), "et"
(Estonian), "fa"
(Persian), "ff"
(Fulah), "fi"
(Finnish), "fil"
(Filipino), "fo"
(Faroese), "fr"
(French), "fr-BE"
(French (Belgium)), "fr-CH"
(French
(Switzerland)), "ga"
(Irish), "he"
(Hebrew), "hi"
(Hindi), "hr"
(Croatian), "hu"
(Hungarian), "hy"
(Armenian), "id"
(Indonesian),
"is"
(Icelandic), "it"
(Italian), "ja"
(Japanese), "ka"
(Georgian),
"kk"
(Kazakh), "kl"
(Kalaallisut), "km"
(Khmer), "ko"
(Korean),
"ky"
(Kyrgyz), "lb"
(Luxembourgish), "lo"
(Lao), "lrc"
(Northern
Luri), "lt"
(Lithuanian), "lv"
(Latvian), "mk"
(Macedonian), "ms"
(Malay), "mt"
(Maltese), "my"
(Burmese), "ne"
(Nepali), "nl"
(Dutch),
"nn"
(Norwegian Nynorsk), "no"
(Norwegian), "pl"
(Polish), "pt"
(Portuguese), "qu"
(Quechua), "ro"
(Romanian), "ru"
(Russian), "se"
(Northern Sami), "sk"
(Slovak), "sl"
(Slovenian), "sq"
(Albanian),
"sr"
(Serbian), "sr-Latn"
(Serbian (Latin)), "su"
(Sundanese), "sv"
(Swedish), "sw"
(Swahili), "ta"
(Tamil), "th"
(Thai), "tr"
(Turkish),
"uk"
(Ukrainian), "vi"
(Vietnamese), "yue"
(Cantonese), and "zh"
(Chinese).
Let's create a numeric vector for the next few examples:
num_vals <- c(1, 8, 23, 76, 0, -5, 200, NA)
Using vec_fmt_spelled_num()
will create a character vector with values
rendered as spelled-out numbers. Any NA
values remain as NA
values. The
rendering context will be autodetected unless specified in the output
argument (here, it is of the "plain"
output type).
vec_fmt_spelled_num(num_vals)
#> [1] "one" "eight" "twenty-three" "seventy-six" "zero" #> [6] "-5" "200" "NA"
If we are formatting for a different locale, we could supply the locale ID and let gt obtain a locale-specific set of spelled numbers:
vec_fmt_spelled_num(num_vals, locale = "af")
#> [1] "een" "agt" "drie-en-twintig" "ses-en-sewentig" #> [5] "nul" "-5" "200" "NA"
As a last example, one can wrap the values in a pattern with the pattern
argument. Note here that NA
values won't have the pattern applied.
vec_fmt_spelled_num(num_vals, pattern = "{x}.")
#> [1] "one." "eight." "twenty-three." "seventy-six." "zero." #> [6] "-5." "200." "NA"
15-11
v0.9.0
(Mar 31, 2023)
The variant function intended for formatting gt table data:
fmt_spelled_num()
.
Other vector formatting functions:
vec_fmt_bytes()
,
vec_fmt_currency()
,
vec_fmt_date()
,
vec_fmt_datetime()
,
vec_fmt_duration()
,
vec_fmt_engineering()
,
vec_fmt_fraction()
,
vec_fmt_index()
,
vec_fmt_integer()
,
vec_fmt_markdown()
,
vec_fmt_number()
,
vec_fmt_partsper()
,
vec_fmt_percent()
,
vec_fmt_roman()
,
vec_fmt_scientific()
,
vec_fmt_time()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.