相关疑难解决方法(0)

将整数转换为单词

为了使数据可视化样式化,我希望能够使用单词显示整数(例如

“ 217年”

)而不是数字(例如2017)。

作为我要寻找的示例,下面是一个适用于小的标量整数的快速函数:

int_to_words <- function(x) {

                   index <- as.integer(x) + 1
                   words <- c('zero', 'one', 'two', 'three', 'four',
                              'five', 'six', 'seven', 'eight', 'nine',
                              'ten')
                   words[index]
}


int_to_words(5)
Run Code Online (Sandbox Code Playgroud)

r

1
推荐指数
2
解决办法
1547
查看次数

标签 统计

r ×1