【发布时间】:2016-06-20 04:24:47
【问题描述】:
下表(平均值±标准差)包含将在出版物中呈现的真实数据。如您所见,数据范围非常广泛。使用 R,我将所有数字四舍五入为 3 个有效数字,但我想包括尾随零以及小数点左侧的零作为重要数字,以保持表格整洁。所以基本上我希望小数点两侧的所有数字(包括零)都被认为是重要的,因此无论数字如何,都只打印 3 位数字。这可能吗?我试过signif、round、sprintf、options()和formatC,但没有成功。
这些结果是使用x$summary = paste(signif(x$Value, digits=3), "\u00b1", signif(x$se, digits=3))获得的
35.2 ± 3.13 > this is good
124 ± 14.8 > this is good
196 ± 6.53 > this is good
1.34 ± 0.0505 > I would like this to become 1.34 ± 0.05
0.0443 ± 0.00386 > I would like this to become 0.04 ± 0.00
123 ± 0.0067 > I would like this to become 123 ± 0.01
【问题讨论】:
-
你从什么开始?现在它们是字符串,而不是数字。如果需要,您可以使用
strsplit和as.numeric转换回来。另外,您想要的输出是什么样的? -
显得模棱两可。你到底想看什么?
-
@alistaire 我编辑了问题以帮助澄清
-
如果
x是现有均值和错误的特征向量,使用purrr只是因为类似strsplit(x, ' ± ') %>% map(as.numeric) %>% map(round, digits = 2) %>% map_chr(paste, collapse = ' ± ')
标签: r rounding standard-error significant-digits