为了美化数据可视化,我希望能够用文字(例如“二千零十七”)而不是数字(例如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)