Install required packages:
#install.packages("htmlwidgets")
#install.packages("rpivotTable")
Load the package:
library(rpivotTable)
It is not needed to load the htmlwidgets to explicitly as it is done automatically.
Let’s load the builtin Titanic dataset from R:
data(Titanic)
If we want to see % of servived among the Titanic Passengers by Class and Sex:
rpivotTable(Titanic,
cols = "Survived",
rows = c("Class","Sex"),
aggregatorName = "Sum as Fraction of Rows",
vals = "Freq",
rendererName = "Table")
Use height with appropriate parameter to minimize the gap after the table:
rpivotTable(Titanic,
cols = "Survived",
rows = c("Class","Sex"),
aggregatorName = "Sum as Fraction of Rows",
vals = "Freq",
rendererName = "Table",
height="400px")
If you have problems with R Studio homework - experts at www.homeworkhelponline.net can take care of your assignments.
If we want to transform the rows into column and columns into rows without effecting the values:
rpivotTable(Titanic,
rows = "Survived",
cols = c("Class","Sex"),
aggregatorName = "Sum as Fraction of Columns",
vals = "Freq",
rendererName = "Table",
height="400px")
More example:
rpivotTable(Titanic,
rows = "Survived",
cols = c("Class","Sex"),
aggregatorName = "Sum as Fraction of Columns", # notice the change in here also
vals = "Freq",
rendererName = "Table Barchart",
height="400px")