1

I'm trying to recreate a pivot-table like dataframe in R Studio with the library(pivottabler).

I have managed to recreate it almost exactly the way I would like it, but the current default pivot tables rendered includes the subtotals and totals which I need removed.

Would anyone happen to know any way I can edit the rows within the pivot table rendered?

1 Answers1

3

I am the package author.

Subtotals can be removed as shown on the seventh line below:

library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC", totalCaption="Grand Total")    #    << Change Total Caption
pt$addRowDataGroups("PowerType")
pt$addRowDataGroups("SchedSpeedMPH", addTotal=FALSE)      #    << Hide Total
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

More bespoke edits to Pivot Table layout can be done by converting the pivot table to a basic table - see under the "Results as a basictabler Table" heading in the "5. Outputs" vignette in the package which is also available here.

cbailiss
  • 1,304
  • 11
  • 21