【问题标题】:pivottabler: formating numbers with commapivottabler:用逗号格式化数字
【发布时间】:2021-08-07 19:18:04
【问题描述】:

我想知道如何使用 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()")

【问题讨论】:

    标签: r pivottabler


    【解决方案1】:

    因为函数被评估为vignette中提到的表达式

    ... 指定计算。 summarise 表达式必须是可以与 dplyr summarise() 函数一起使用的表达式。该表达式由具有 dplyr 汇总函数的 pivottabler 包在内部使用。

    我们可以用commaformattable包装那些

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

    -输出


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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-31
      • 2020-12-18
      • 2017-12-09
      • 2011-11-08
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      相关资源
      最近更新 更多