How to convert rpivotTable result in to dataframe. I want to create new datafrmae with the result of rpivotTable,
Is it possible do in R?
Data Set Like
User Order_Bin
a PPL
b CCD
c CCD
d OLP
a OLP
c PPL
b OLP
a PPL
a OLP
b PPL
c CCD
d CCD
d OLP
c OLP
b OLP
b CCD
How to get result of below code as data.frame
library(rpivotTable)
rpivotTable(
inventory,
aggregatorName = "Count",
cols = "Order_Bin",
rows = "User",
rendererName = "Heatmap",
width = "100%",
height = "1000px")
According to the documention of rpivotTable
, there is no export facility.
So, you have to aggregate on your own. One possibility is
reshape2::dcast(inventory, User ~ Order_Bin, length, margins = TRUE)
which returns
User CCD OLP PPL (all) 1 a 0 2 2 4 2 b 2 2 1 5 3 c 2 1 1 4 4 d 1 2 0 3 5 (all) 5 7 4 16
For comparison, here is the output of the pivotTable()
call:
Please, note the Totals row and column.