The rpivotTable package depends on htmlwidgets package so you need to install both packages. You can do this using the devtools package as follows:
Call the package with
library(rpivotTable) # No need to explicitly load htmlwidgets: this is done automatically
Just plug in your
data.table (e.g. dt) to
It is as simple as this:
The pivot table should appear in your RStudio Viewer or your browser of choice.
Please refer to the examples and explanations here.
rpivotTable parameters decide how the pivot table will look like the firs time it is opened:
datacan be a
data.table. Nothing else is needed. If only the data is selected the pivot table opens with nothing on rows and columns (but you can at any time drag and drop any variable in rows or columns at your leasure)
colsallow the user to create a report, i.e. to indicate which element will be on rows and columns.
aggregatorNameindicates the type of aggregation. Options here are numerous: Count, Count Unique Values, List Unique Values, Sum, Integer Sum, Average, Sum over Sum, 80% Upper Bound, 80% Lower Bound, Sum as Fraction of Total, Sum as Fraction of Rows, Sum as Fraction of Columns, Count as Fraction of Total, Count as Fraction of Rows, Count as Fraction of Columns
valsspecifies the variable to use with
renderersdictates the type of graphic element used for display, like Table, Treemap etc.
subtotalswill allow to dynamically select / deselect subtotals
For example, to display a pivot table with frequency of colour combinations of eyes and hair, you can specify:
data(HairEyeColor) rpivotTable(data = HairEyeColor, rows = "Hair",cols="Eye", vals = "Freq", aggregatorName = "Sum", rendererName = "Table", width="100%", height="400px")
This will display a cross tab with the frequency of eyes by hair colour. Dragging & dropping (slicing & dicing) categorical variables in rows and columns changes the shape of the table.
If you want to include it as part of your
magrittr pipeline, you can do that also:
library(dplyr) iris %>% tbl_df() %>% filter( Sepal.Width > 3 ) %>% rpivotTable()
I’m happy to announce that Nicolas Kruchten has officialy joined the rpivotTable project. Many thanks to him for the work on the current release.