0

I need thousand separators with points and decimal separators with comma. My data is bhmtrains, pivottabler library .

I´m using this code:

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

Example: Input:12000.2

Output: 12.000,2

1 Answers1

2

This can be done by specifying the format settings for each calculation as a list. The elements in the list are passed as arguments to the R base::format() function by pivottabler.

As an example, starting from this sample data (since the sample data in the question was confusing me by having a standard deviation as a percentage):

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

enter image description here

Specifying format settings as lists:

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

Result:

enter image description here

cbailiss
  • 1,304
  • 11
  • 21