num_as_ordinal {ds4psy} | R Documentation |
Convert a number into an ordinal character sequence.
Description
num_as_ordinal
converts a given (cardinal) number
into an ordinal character sequence.
Usage
num_as_ordinal(x, sep = "")
Arguments
x |
Number(s) to convert (required, scalar or vector). |
sep |
Decimal separator to use.
Default: |
Details
The function currently only works for the English language and does not accepts inputs that are characters, dates, or times.
Note that the toOrdinal()
function of the toOrdinal package works
for multiple languages and provides a toOrdinalDate()
function.
Caveat: Note that this function illustrates how numbers,
characters, for
loops, and paste()
can be combined
when writing functions.
It is instructive, but not written efficiently or well
(see the function definition for an alternative solution
using vector indexing).
See Also
toOrdinal()
function of the toOrdinal package.
Other numeric functions:
base2dec()
,
base_digits
,
dec2base()
,
is_equal()
,
is_wholenumber()
,
num_as_char()
,
num_equal()
Other utility functions:
base2dec()
,
base_digits
,
dec2base()
,
is_equal()
,
is_vect()
,
is_wholenumber()
,
num_as_char()
,
num_equal()
Examples
num_as_ordinal(1:4)
num_as_ordinal(10:14) # all with "th"
num_as_ordinal(110:114) # all with "th"
num_as_ordinal(120:124) # 4 different suffixes
num_as_ordinal(1:15, sep = "-") # using sep
# Note special cases:
num_as_ordinal(NA)
num_as_ordinal("1")
num_as_ordinal(Sys.Date())
num_as_ordinal(Sys.time())
num_as_ordinal(seq(1.99, 2.14, by = .01))