Getting started with toOrdinal

Damian W Betebenner

February 22nd, 2019

Introduction

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,

Use

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.

Since Version 1.1, the function toOrdinalDate converts calendar dates to a long format, ordinal form.

> toOrdinalDate()
[1] "February 22nd, 2019"
> toOrdinalDate("2017-12-25")
[1] "December 25th, 2017"

If no argument is provided to toOrdinalDate, then the current date derived from Sys.date() is used to create the ordinal version of the calendar date. If a date is supplied, then it must be supplied as a character string of the form “YYYY-MM-DD” that is then converted to the more formal date format. Like with the function toOrdinal the potential exists for multiple language support with toOrdinalDate. However, the only language currently supported by toOrdinalDate is English.

Examples

The first argument, n, is the cardinal number to be converted to an ordinal number:

Contributions & Requests

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).