[英]create a sequence of numbers written in letters
How can I create a sequence of numbers but those numbers should be written in letters, ie "one" instead of 1 / "two" instead of 2. I want to create a vector of numbers from 100 to 1 (in reverse order) and the numbers need to be written in letters. 如何创建数字序列,但是这些数字应该用字母写成,即“一个”而不是1 /“两个”而不是2。我想创建一个从100到1(以相反顺序)的数字矢量,并且数字需要用字母书写。 TIA
TIA
You can use the english
package for this. 您可以为此使用
english
包。
library(english)
as.english(100:1)
[1] one hundred ninety nine ninety eight ninety seven ...
Or for character output: 或用于字符输出:
words(100:1)
[1] "one hundred" "ninety nine" "ninety eight" "ninety seven" ...
Edit: As neilfws notes words()
will produce character strings which might be more useful if you want to continue to process the data. 编辑:正如neilfws所说,
words()
将产生字符串,如果您想继续处理数据,则可能会更有用。 as.english()
is a print/format method. as.english()
是一种打印/格式化方法。
Copy and paste this R function . 复制并粘贴此R函数 。
Then run: 然后运行:
numbers2words(100:1)
Testing using 10 to 1 (100 to 1 works, but I didn't want to paste the large output here): 使用10到1进行测试(100到1有效,但是我不想在此处粘贴较大的输出):
numbers2words(10:1)
[1] "ten" "nine" "eight" "seven" "six" "five" "four" "three" "two" "one"
EDIT: better still use english::words(100:1)
as in the answer from H 1. 编辑:最好仍使用
english::words(100:1)
作为H 1的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.