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

旧时模样 提交于 2021-02-09 08:27:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!