R中是否有显示用逗号分隔的大数字的功能?

即,从 10000001,000,000

最佳答案

您可以尝试 format 或 prettyNum,但这两个函数都返回一个字符向量。我只会用它来打印。

> prettyNum(12345.678,big.mark=",",scientific=FALSE)
[1] "12,345.68"
> format(12345.678,big.mark=",",scientific=FALSE)
[1] "12,345.68"

编辑:正如 Michael Chirico 在评论中所说:

请注意,这些具有用空格填充打印字符串的副作用,例如:
> prettyNum(c(123,1234),big.mark=",")
[1] "  123" "1,234"

trim=TRUE 添加到 formatpreserve.width="none"prettyNum 以防止出现这种情况:
> 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 - R中数字的逗号分隔符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3838774/

10-12 19:54