本文介绍了R中数字的逗号分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
R 中是否有显示用逗号分隔的大数字的函数?
Is there a function in R to display large numbers separated with commas?
即,从 1000000
到 1,000,000
.
推荐答案
您可以尝试 format 或 prettyNum,但这两个函数都返回一个字符向量.我只会用它来打印.
You can try either format or prettyNum, but both functions return a vector of characters. I'd only use that for printing.
> prettyNum(12345.678,big.mark=",",scientific=FALSE)
[1] "12,345.68"
> format(12345.678,big.mark=",",scientific=FALSE)
[1] "12,345.68"
正如 Michael Chirico 在评论中所说:
As Michael Chirico says in the comment:
请注意,这些具有用空格填充打印字符串的副作用,例如:
Be aware that these have the side effect of padding the printed strings with blank space, for example:
> prettyNum(c(123,1234),big.mark=",")
[1] " 123" "1,234"
将 trim=TRUE
添加到 format
或将 preserve.width="none"
添加到 prettyNum
以防止这种情况:
Add trim=TRUE
to format
or preserve.width="none"
to prettyNum
to prevent this:
> prettyNum(c(123,1234),big.mark=",", preserve.width="none")
[1] "123" "1,234"
> format(c(123,1234),big.mark=",", trim=TRUE)
[1] "123" "1,234"
这篇关于R中数字的逗号分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!