The qpvt function builds a basic pivot table with one line of R.

qpvt(
  dataFrame,
  rows = NULL,
  columns = NULL,
  calculations = NULL,
  theme = NULL,
  replaceExistingStyles = FALSE,
  tableStyle = NULL,
  headingStyle = NULL,
  cellStyle = NULL,
  totalStyle = NULL,
  ...
)

Arguments

dataFrame

The data frame containing the data to be summarised in the pivot table.

rows

A character vector of variable names to be plotted on the rows of the pivot table, or "=" to specify the position of the calculations.

columns

A character vector of variable names to be plotted on the columns of the pivot table, or "=" to specify the position of the calculations.

calculations

One or more summary calculations to use to calculate the values of the cells in the pivot table.

theme

Either the name of a built-in theme (default, largeplain, compact or blank/none) or a list which specifies the default formatting for the table.

replaceExistingStyles

TRUE to completely replace the default styling with the specified tableStyle, headingStyle, cellStyle and/or totalStyle

tableStyle

A list of CSS style declarations that apply to the table.

headingStyle

A list of CSS style declarations that apply to the heading cells in the table.

cellStyle

A list of CSS style declarations that apply to the normal cells in the table.

totalStyle

A list of CSS style declarations that apply to the total cells in the table.

...

Additional arguments, currently format, formats, totals, compatibility and/or argumentCheckMode.

Value

A pivot table.

Examples

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  
qpvt(bhmtrains, c("=", "TOC"), c("TrainCategory", "PowerType"),
     c("Number of Trains"="n()",
       "Maximum Speed"="max(SchedSpeedMPH, na.rm=TRUE)"))
#>                                        Express Passenger         Ordinary Passenger  Total  
#>                                        DMU    EMU    HST  Total  DMU   EMU    Total         
#> Number of Trains  Arriva Trains Wales   3079               3079   830           830   3909  
#>                   CrossCountry         22133         732  22865    63            63  22928  
#>                   London Midland        5638   8849       14487  5591  28201  33792  48279  
#>                   Virgin Trains         2137   6457        8594                       8594  
#>                   Total                32987  15306  732  49025  6484  28201  34685  83710  
#> Maximum Speed     Arriva Trains Wales     90                 90    90            90     90  
#>                   CrossCountry           125         125    125   100           100    125  
#>                   London Midland         100    110         110   100    100    100    110  
#>                   Virgin Trains          125    125         125                        125  
#>                   Total                  125    125  125    125   100    100    100    125