The package toOrdinal contains a single function toOrdinal
that converts a cardinal number (e.g., 9) into its ordinal counterpart (e.g., 9th). Because such conversions are language specific, the conversions are specific to a supported language. At present, the package implements English, French, German, Spanish, and Swedish. For example,
After installing the package from either CRAN or GitHub, it’s simple to convert a cardinal to an ordinal number.
To convert cardinal to ordinal numbers in English (the default), supply the cardinal number to toOrdinal
.
> toOrdinal(5)
[1] "5th"
Conversion in other languages are performed by supplying the appropriate language to the language
argument:
> toOrdinal(5, language="German")
[1] "5te"
> toOrdinal(5, language="French")
[1] "5e"
> toOrdinal(5, language="Spanish")
[1] "5.º"
> toOrdinal(5, language="Swedish")
[1] "5:e"
Current languages supported include: English, German, French, Spanish, and Swedish.
The first argument, n
, is the cardinal number to be converted to an ordinal number:
> sapply(1:10, toOrdinal)
[1] "1st" "2nd" "3rd" "4th" "5th" "6th" "7th" "8th" "9th" "10th"
If you have contribution (for example, another language) or a feature request for the toOrdinal package, don’t hesitate to write or set up an issue on GitHub. Current new features include the possiblity of converting cardinal numbers to ordinal words (e.g., 8 to eighth).