为了使数据可视化样式化,我希望能够使用单词显示整数(例如
“ 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