如何将整数转换为字符串文字?

时间:2014-12-03 13:35:31

标签: r

是否有将整数转换为英语等值的函数?即实现转型:

some_function(1) = 'one'

2 个答案:

答案 0 :(得分:5)

使用english

library(english)
english(1:10)
# [1] one   two   three four  five  six   seven eight nine  ten  

答案 1 :(得分:3)

some_function <- function(i) {
     stopifnot(i %in% 1:9)
     lookup <- c("one", "two", "three",
                 "four", "five", "six",
                 "seven", "eight", "nine")
     lookup[i]
}

根据需要进行修改。