R中数字的逗号分隔符? [英] Comma separator for numbers in R?

查看:58
本文介绍了R中数字的逗号分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a function in R to display large numbers separated with commas?

即,从 10000001,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中数字的逗号分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆