我想知道如何使用qpvt和qhpvt函数从pivottabler R包中用逗号显示数字。
library(pivottabler)
qpvt(bhmtrains, "TOC", "TrainCategory", "n()")
Express Passenger Ordinary Passenger Total
Arriva Trains Wales 3079 830 3909
CrossCountry 22865 63 22928
London Midland 14487 33792 48279
Virgin Trains 8594 8594
Total 49025 34685 83710
qhpvt(bhmtrains, "TOC", "TrainCategory", "n()")发布于 2021-08-07 19:37:46
,因为函数作为表达式计算,如vignette中提到的那样
...指定计算。概要表达式必须是一个可以与dplyr汇总()函数一起使用的表达式。这个表达式由带有dplyr汇总函数的透视包内部使用。
我们可以用comma从formattable包装这些
library(pivottabler)
qhpvt(bhmtrains, "TOC", "TrainCategory", "formattable::comma(n(), digits = 0)")-output

还有一个format/formats参数,我们可以在该参数上使用单一格式或格式列表(当使用多个表达式时),即如果我们要显示数字
qhpvt(bhmtrains, "TOC", "TrainCategory", "n()", format = "%.2f" )

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