问题
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?
回答1:
from library(english)
ordinal(1:5)
# [1] first second third fourth fifth
回答2:
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 ...
来源:https://stackoverflow.com/questions/53147450/is-there-a-build-in-ordinal-sequence-vector-in-r