gpt4 book ai didi

r - 将整数转换为单词

转载 作者:行者123 更新时间:2023-12-03 15:06:44 27 4
gpt4 key购买 nike

出于样式化数据可视化的目的,我希望能够使用单词(例如

"Two thousand and seventeen"



) 而不是数字(例如 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)

最佳答案

选项 1:

使用 as.english 'english' 包中的函数:

library(english)

as.english(2017)

选项 2:

使用 replace_number 'qdap' 包中的函数。
library(qdap)

replace_number(2017)

选项 3:

使用 numbers_to_words 'xfun' 包中的函数。
library(xfun)

numbers_to_words(2017)

关于r - 将整数转换为单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46652066/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com