Leonhardt Guass
Leonhardt Guass

Reputation: 793

Is there a build-in ordinal sequence vector in R?

I need a long ordinal sequence vector in R. As a simple example of what I want:

OS <- c("First","Second","Third")

Is there a build-in vector like that?

Upvotes: 4

Views: 1563

Answers (2)

Ben Bolker
Ben Bolker

Reputation: 226192

I googled "R cardinal numbers" and got to the vignette for the toOrdinal package, but unfortunately it doesn't actually get you words.

library(toOrdinal)
sapply(1:5,toOrdinal)
## [1] "1st" "2nd" "3rd" "4th" "5th"

The docs say

convert_to: OPTIONAL. Output type that provided 'cardinal_number' is converted into. Default is 'ordinal_number' which refers to the 'cardinal_number' followed by the appropriate ordinal indicator. Additional options planned include 'ordinal_word'.

so maybe this will eventually do what you want ...

Upvotes: 2

dww
dww

Reputation: 31452

from library(english)

ordinal(1:5)
# [1] first  second third  fourth fifth 

Upvotes: 9

Related Questions