我需要一千个分隔符与点和小数分隔符逗号。我的数据是bhmtrains,pivottabler库。
我使用的是以下代码:
library(pivottabler)
qhpvt(bhmtrains, "TOC", "TrainCategory",
c("Mean Speed"="format(sum(SchedSpeedMPH, na.rm=TRUE))", "Std Dev Speed"="sd(SchedSpeedMPH,na.rm=TRUE)"),
formats=list("%.0f", "%.1f%%"), totals=list("TOC"="All TOCs", "TrainCategory"="All Categories"))示例:输入:12000.2
输出: 12.000,2
发布于 2020-01-15 02:53:37
这可以通过将每个计算的格式设置指定为列表来实现。pivottabler将列表中的元素作为参数传递给R base::format()函数。
例如,从这个样本数据开始(因为问题中的样本数据以百分比表示的标准差让我感到困惑):
library(pivottabler)
qhpvt(bhmtrains, "TOC", "TrainCategory",
c("Value 1"="mean(SchedSpeedMPH, na.rm=TRUE)*33.33333",
"Value 2"="sd(SchedSpeedMPH,na.rm=TRUE)*333.33333"),
formats=list("%.5f", "%.5f"),
totals=list("TOC"="All TOCs", "TrainCategory"="All Categories"))

将格式设置指定为列表:
library(pivottabler)
qhpvt(bhmtrains, "TOC", "TrainCategory",
c("Value 1"="mean(SchedSpeedMPH, na.rm=TRUE)*33.33333",
"Value 2"="sd(SchedSpeedMPH,na.rm=TRUE)*333.33333"),
formats=list(list(digits=1, nsmall=0, big.mark=".", decimal.mark=","),
list(digits=1, nsmall=1, big.mark=".", decimal.mark=",")),
totals=list("TOC"="All TOCs", "TrainCategory"="All Categories"))结果:

https://stackoverflow.com/questions/59201901
复制相似问题