All Projects → cbailiss → pivottabler

cbailiss / pivottabler

Licence: other
Create Pivot Tables natively in R

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to pivottabler

Blazor Samples
Explore and learn Syncfusion Blazor components using large collection of demos, example applications and tutorial samples
Stars: ✭ 156 (+44.44%)
Mutual labels:  pivot-tables
basictabler
Construct Rich Tables for Output to HTML/Excel
Stars: ✭ 34 (-68.52%)
Mutual labels:  htmlwidget
pivot-angular
Integration example of WebDataRocks web reporting tool with Angular 2+ framework
Stars: ✭ 30 (-72.22%)
Mutual labels:  pivot-tables
Vue Pivot Table
A vue component for pivot table
Stars: ✭ 162 (+50%)
Mutual labels:  pivot-tables
pivot-react
Integration of Flexmonster Pivot Table & Charts with React framework
Stars: ✭ 23 (-78.7%)
Mutual labels:  pivot-tables
PyArmadillo
PyArmadillo: an alternative approach to linear algebra in Python
Stars: ✭ 58 (-46.3%)
Mutual labels:  calculations
Generators
Laravel File Generators with config and publishable stubs
Stars: ✭ 102 (-5.56%)
Mutual labels:  pivot-tables
bpmn
BPMN diagrams in R
Stars: ✭ 16 (-85.19%)
Mutual labels:  htmlwidget
tfsaggregator
A server side plugin for Team Foundation Server (TFS) and Azure DevOps Server for performing various Work Item related calculations, create new Work Items and Links automatically.
Stars: ✭ 122 (+12.96%)
Mutual labels:  calculations
MathExpressions.NET
➗ Library for parsing math expressions with rational numbers, finding their derivatives and compiling an optimal IL code
Stars: ✭ 63 (-41.67%)
Mutual labels:  calculations
Ditching Excel For Python
Functionalities in Excel translated to Python
Stars: ✭ 172 (+59.26%)
Mutual labels:  pivot-tables
Tad
A desktop application for viewing and analyzing tabular data
Stars: ✭ 2,275 (+2006.48%)
Mutual labels:  pivot-tables
lineup htmlwidget
HTMLWidget wrapper of LineUp for Visual Analysis of Multi-Attribute Rankings
Stars: ✭ 51 (-52.78%)
Mutual labels:  htmlwidget
Ej2 Angular Ui Components
Syncfusion Angular UI components library offer more than 50+ cross-browser, responsive, and lightweight angular UI controls for building modern web applications.
Stars: ✭ 159 (+47.22%)
Mutual labels:  pivot-tables
web-pivot-table
A feature-rich JS pivot grid library for creating interactive reports. Integrates with any front-end technology
Stars: ✭ 35 (-67.59%)
Mutual labels:  pivot-tables
Unpivotr
Unpivot complex and irregular data layouts in R
Stars: ✭ 148 (+37.04%)
Mutual labels:  pivot-tables
PivotHelper
PivotHelper is a utility web app that generates Pivot tables and charts from CSV files and Microsoft Excel spreadsheets.
Stars: ✭ 26 (-75.93%)
Mutual labels:  pivot-tables
earthcalc
This app calculates how much a distant object is obscured by the earth's curvature.
Stars: ✭ 74 (-31.48%)
Mutual labels:  calculations
frechet
Discrete Fréchet distance and of the minimum path required for traversing with it
Stars: ✭ 14 (-87.04%)
Mutual labels:  calculations
taucharts
📊 An R htmlwidget interface to the TauCharts javascript library
Stars: ✭ 66 (-38.89%)
Mutual labels:  htmlwidget

pivottabler

R-CMD-check CRAN_Status_Badge CRAN RStudio mirror downloads

The pivottabler package enables pivot tables to be created with just a few lines of R.

The pivottabler package aims to:

  • Provide an easy way of creating pivot tables, without requiring the user to specify low-level layout logic.
  • Provide multiple ways of specifying calculation logic to cover both simple and more sophisticated requirements.
  • Provide styling options so the pivot tables can be themed/branded as needed.

All calculations for the pivot tables take place inside R, enabling the use of a wide-range of R functions in the calculation logic.

Pivot tables are rendered as htmlwidgets, Latex or plain text. The HTML/Latex/text can be exported for use outside of R.

Pivot tables can be converted to a standard R matrix or data frame. Pivot tables can be exported to Excel. Pivot tables can also be converted to a basictabler table for further manipulation.

Using the flextabler package it is also possible to output tables to Word and PowerPoint.

pivottabler is a companion package to the basictabler package. pivottabler is focussed on generating pivot tables and can aggregate data. basictabler does not aggregate data but offers more control of table structure.

For more detailed information see http://www.pivottabler.org.uk/articles.

Installation

You can install:

  • the latest released version from CRAN with
install.packages("pivottabler")
  • the latest development version from GitHub with
devtools::install_github("cbailiss/pivottabler", build_vignettes = TRUE)

Example

pivottabler has many styling and formatting capabilities when rendering pivot tables in HTML / as htmlwidgets using pt$renderPivot(), however the most basic output is simply as plain text.

Plain Text Output

A simple example of creating a pivot table - summarising the types of trains run by different train companies:

library(pivottabler)
# arguments:  qpvt(dataFrame, rows, columns, calculations, ...)
qpvt(bhmtrains, "TOC", "TrainCategory", "n()") # TOC = Train Operating Company 
                     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  

pivottabler also offers a more verbose syntax that is more self-describing and offers additional options that aren't available with the quick-pivot functions. The equivalent verbose commands to output the same pivot table as above are:

library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains) # bhmtrains is a data frame with columns TrainCategory, TOC, etc.
pt$addColumnDataGroups("TrainCategory") # e.g. Express Passenger
pt$addRowDataGroups("TOC") # TOC = Train Operating Company e.g. Arriva Trains Wales
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$evaluatePivot()
pt

Multiple levels can be added to the pivot table row or column headings, e.g. looking at combinations of TOC and PowerType:

library(pivottabler)
qpvt(bhmtrains, c("TOC", "PowerType"), "TrainCategory", "n()")
library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$addRowDataGroups("PowerType") # D/EMU = Diesel/Electric Multiple Unit, HST=High Speed Train
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$evaluatePivot()
pt
                            Express Passenger  Ordinary Passenger  Total  
Arriva Trains Wales  DMU                 3079                 830   3909  
                     Total               3079                 830   3909  
CrossCountry         DMU                22133                  63  22196  
                     HST                  732                        732  
                     Total              22865                  63  22928  
London Midland       DMU                 5638                5591  11229  
                     EMU                 8849               28201  37050  
                     Total              14487               33792  48279  
Virgin Trains        DMU                 2137                       2137  
                     EMU                 6457                       6457  
                     Total               8594                       8594  
Total                                   49025               34685  83710  

HTML Output

The HTML rendering of the same two pivot tables shown above (each constructed using both a quick-pivot function and verbose syntax) is:

library(pivottabler)
qhpvt(bhmtrains, "TOC", "TrainCategory", "n()") 
library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains) 
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

http://cbailiss.me.uk/pivottablerreadmeimgs/example1.png

library(pivottabler)
qhpvt(bhmtrains, c("TOC", "PowerType"), "TrainCategory", "n()")  
library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains) # bhmtrains is a data frame with columns TrainCategory, TOC, etc.
pt$addColumnDataGroups("TrainCategory") # e.g. Express Passenger
pt$addRowDataGroups("TOC") # TOC = Train Operating Company e.g. Arriva Trains Wales
pt$addRowDataGroups("PowerType") # D/EMU = Diesel/Electric Multiple Unit, HST=High Speed Train
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

http://cbailiss.me.uk/pivottablerreadmeimgs/example2.png

Outline layout is an alternative way of rendering the row groups, e.g. for the same pivot table as above:

library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains) 
pt$addColumnDataGroups("TrainCategory") 
pt$addRowDataGroups("TOC", 
                    outlineBefore=list(isEmpty=FALSE, groupStyleDeclarations=list(color="blue")), 
                    outlineTotal=list(isEmpty=FALSE, groupStyleDeclarations=list(color="blue"))) 
pt$addRowDataGroups("PowerType", addTotal=FALSE) 
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

http://cbailiss.me.uk/pivottablerreadmeimgs/example7.png

Outline layout can also be used to build a pivot table with a variable depth hierarchy on the rows, e.g. a simple balance sheet:

http://cbailiss.me.uk/pivottablerreadmeimgs/example8.png

The R for generating the above pivot table can be found in the Regular Layout vignette at http://www.pivottabler.org.uk/articles.

Multiple Calculations

Multiple calculations are supported. Calculations can be based on other calculations in the pivot table. Calculations can be hidden - e.g. to hide calculations that only exist to provide values to other calculations.

For example, looking at the total number of trains and the percentage of trains that arrive more than five minutes late for combinations of train operating company (TOC) and train category:

library(pivottabler)
library(dplyr)
library(lubridate)

# derive train delay data
trains <- mutate(bhmtrains,
                 ArrivalDelta=difftime(ActualArrival, GbttArrival, units="mins"),
                 ArrivalDelay=ifelse(ArrivalDelta<0, 0, ArrivalDelta),
                 DelayedByMoreThan5Minutes=ifelse(ArrivalDelay>=5,1,0))

# create the pivot table
pt <- PivotTable$new()
pt$addData(trains)
pt$addRowDataGroups("TOC", totalCaption="All TOCs")
pt$addColumnDataGroups("TrainCategory", totalCaption="All Trains")
pt$defineCalculation(calculationName="TotalTrains", caption="Train Count", 
                     summariseExpression="n()")
pt$defineCalculation(calculationName="DelayedTrains", caption="Trains Arr. 5+ Mins Late", 
                     summariseExpression="sum(DelayedByMoreThan5Minutes, na.rm=TRUE)",
                     visible=FALSE)
pt$defineCalculation(calculationName="DelayedPercent", caption="% Late Trains", 
                     type="calculation", basedOn=c("DelayedTrains", "TotalTrains"), 
                     format="%.1f %%",
                     calculationExpression="values$DelayedTrains/values$TotalTrains*100")
pt$renderPivot()

http://cbailiss.me.uk/pivottablerreadmeimgs/example6.png

It is also possible to change the axis (rows or columns) and level in which the calculations appear. See the "Calculations" vignette for details.

More advanced calculations such as % of row total, cumulative sums, etc are possible. See the "A2. Appendix: Calculations" vignette for details.

Styling Example

Styling can be specified when creating the pivot table. The example below shows specifying styling using a quick-pivot function and using the more verbose syntax.

library(pivottabler)
qhpvt(bhmtrains, "TOC", "TrainCategory", "n()", 
      tableStyle=list("border-color"="maroon"),
      headingStyle=list("color"="cornsilk", "background-color"="maroon", 
                        "font-style"="italic", "border-color"="maroon"), 
      cellStyle=list("color"="maroon", "background-color"="cornsilk", 
                     "border-color"="maroon"),
      totalStyle=list("color"="maroon", "background-color"="cornsilk", 
                      "border-color"="maroon", "font-weight"="bold")) 
library(pivottabler)
pt <- PivotTable$new(tableStyle=list("border-color"="maroon"),
                     headingStyle=list("color"="cornsilk", "background-color"="maroon", 
                                       "font-style"="italic", "border-color"="maroon"), 
                     cellStyle=list("color"="maroon", "background-color"="cornsilk", 
                                    "border-color"="maroon"),
                     totalStyle=list("color"="maroon", "background-color"="cornsilk", 
                                     "border-color"="maroon", "font-weight"="bold"))
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

http://cbailiss.me.uk/pivottablerreadmeimgs/example5.png

It is also possible to change the styling of single cells and ranges of cells after the pivot table has been created. See the "Styling" and "Finding and Formatting" vignettes for more details.

Excel Output

The same styling/formatting used for the HTML output is also used when outputting to Excel - greatly reducing the amount of script that needs to be written to create Excel output.

library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains) # bhmtrains is a data frame with columns TrainCategory, TOC, etc.
pt$addColumnDataGroups("TrainCategory") # e.g. Express Passenger
pt$addRowDataGroups("TOC") # TOC = Train Operating Company e.g. Arriva Trains Wales
pt$addRowDataGroups("PowerType") # D/EMU = Diesel/Electric Multiple Unit, HST=High Speed Train
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$evaluatePivot()

library(openxlsx)
wb <- createWorkbook(creator = Sys.getenv("USERNAME"))
addWorksheet(wb, "Data")
pt$writeToExcelWorksheet(wb=wb, wsName="Data", 
                         topRowNumber=2, leftMostColumnNumber=2, applyStyles=TRUE)
saveWorkbook(wb, file="C:\\test.xlsx", overwrite = TRUE)

http://cbailiss.me.uk/pivottablerreadmeimgs/example4.png

In the screenshot above, Gridlines have been made invisible to make the styling easier to see (by clearing the checkbox on the 'View' ribbon). Columns were also auto-sized - though the widths of columns could also be manually specified from R. See the Excel Export vignette for more details.

More Information

More complex pivot tables can also be created, e.g. with irregular layouts, using multiple data frames, using multiple calculations and/or custom R calculation functions.

See http://www.pivottabler.org.uk/articles for more detailed information.

More Examples

The following are a few of the example pivot tables constructed in the package vignettes (click to open full sized picture):

http://cbailiss.me.uk/pivottablerreadmeimgs/example3.png

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].