pivottabler:用逗号格式化数字

pivottabler: formating numbers with comma

我想知道如何使用 pivottabler R 包中的 qpvtqhpvt 函数用逗号显示数字。

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()")

因为函数被计算为 vignette

中提到的表达式

... Specify the calculation. The summarise expression must be an expression that can be used with the dplyr summarise() function. This expression is used internally by the pivottabler package with the dplyr summarise function.

我们可以用 commaformattable

包装那些
library(pivottabler)
qhpvt(bhmtrains, "TOC", "TrainCategory", "formattable::comma(n(), digits = 0)")

-输出


还有一个 format/formats 参数,我们可以在该参数上使用单一格式或格式列表(当使用多个表达式时),即如果我们想显示数字

qhpvt(bhmtrains, "TOC", "TrainCategory", "n()", format = "%.2f" )