![]() ![]() ![]() Value that is displayed in the pivot table. The calculation is based on, e.g. a sum() of numerical values will ![]() RawValue is typically the same data type as the variable That is the result of the calculation in the cell. Library ( dplyr ) library ( lubridate ) library ( pivottabler ) # get the date of each train and whether that date is a weekday or weekend trains % mutate (GbttDateTime = if_else ( is.na ( GbttArrival ), GbttDeparture, GbttArrival ), DayNumber = wday ( GbttDateTime ), WeekdayOrWeekend = ifelse ( DayNumber %in% c ( 1, 7 ), "Weekend", "Weekday" ) ) # render the pivot table pt <- PivotTable $ new ( ) pt $ addData ( trains ) pt $ addColumnDataGroups ( "TrainCategory" ) pt $ addRowDataGroups ( "TOC" ) weekendFilter <- PivotFilters $ new ( pt, variableName = "WeekdayOrWeekend", values = "Weekend" ) pt $ defineCalculation (calculationName = "WeekendTrains", summariseExpression = "n()", filters = weekendFilter, visible = FALSE ) pt $ defineCalculation (calculationName = "TotalTrains", summariseExpression = "n()", visible = FALSE ) pt $ defineCalculation (calculationName = "WeekendTrainsPercentage", type = "calculation", basedOn = c ( "WeekendTrains", "TotalTrains" ), format = "%.1f %%", calculationExpression = "values$WeekendTrains/values$TotalTrains*100" ) pt $ renderPivot ( )Įach cell in a pivot table has two values: A rawValue 5+ Mins Late", type = "calculation", basedOn = c ( "DelayedTrains", "TotalTrains" ), format = "%.1f %%", calculationExpression = "values$DelayedTrains/values$TotalTrains*100" ) pt $ renderPivot ( ) Library ( pivottabler ) library ( dplyr ) library ( lubridate ) # derive some additional data trains 5, 1, 0 ) ) # create the pivot table pt <- PivotTable $ new ( ) pt $ addData ( trains ) pt $ addColumnDataGroups ( "GbttMonth", dataFormat = list (format = "%B %Y" ) ) pt $ addRowDataGroups ( "TOC", totalCaption = "All TOCs" ) pt $ defineCalculation (calculationName = "DelayedTrains", visible = FALSE, summariseExpression = "sum(DelayedByMoreThan5Minutes, na.rm=TRUE)" ) pt $ defineCalculation (calculationName = "TotalTrains", visible = FALSE, summariseExpression = "n()" ) pt $ defineCalculation (calculationName = "DelayedPercent", caption = "% Trains Arr. 5+ Mins Late", summariseExpression = "sum(DelayedByMoreThan5Minutes, na.rm=TRUE)" ) pt $ defineCalculation (calculationName = "TotalTrains", caption = "Total Trains", summariseExpression = "n()" ) pt $ defineCalculation (calculationName = "DelayedPercent", caption = "% Trains Arr. Library ( pivottabler ) library ( dplyr ) library ( lubridate ) # derive some additional data trains 5, 1, 0 ) ) # create the pivot table pt <- PivotTable $ new ( ) pt $ addData ( trains ) pt $ addRowDataGroups ( "TOC", totalCaption = "All TOCs" ) pt $ defineCalculation (calculationName = "DelayedTrains", caption = "Trains Arr. Dev.", summariseExpression = "sd(ArrivalDelay, na.rm=TRUE)", format = "%.1f" ) pt $ renderPivot ( ) Delay", summariseExpression = "median(ArrivalDelay, na.rm=TRUE)" ) pt $ defineCalculation (calculationName = "IQRArrivalDelay", caption = "Delay IQR", summariseExpression = "IQR(ArrivalDelay, na.rm=TRUE)" ) pt $ defineCalculation (calculationName = "SDArrivalDelay", caption = "Delay Std. Delay", summariseExpression = "mean(ArrivalDelay, na.rm=TRUE)", format = "%.1f" ) pt $ defineCalculation (calculationName = "MedianArrivalDelay", caption = "Median Arr. Delay", summariseExpression = "max(ArrivalDelay, na.rm=TRUE)" ) pt $ defineCalculation (calculationName = "MeanArrivalDelay", caption = "Mean Arr. Delay", summariseExpression = "min(ArrivalDelay, na.rm=TRUE)" ) pt $ defineCalculation (calculationName = "MaxArrivalDelay", caption = "Max Arr. Library ( pivottabler ) library ( dplyr ) library ( lubridate ) # derive some additional data trains <- mutate ( bhmtrains, ArrivalDelta = difftime ( ActualArrival, GbttArrival, units = "mins" ), ArrivalDelay = ifelse ( ArrivalDelta < 0, 0, ArrivalDelta ) ) # create the pivot table pt <- PivotTable $ new ( ) pt $ addData ( trains ) pt $ addRowDataGroups ( "TOC", totalCaption = "All TOCs" ) pt $ defineCalculation (calculationName = "TotalTrains", caption = "Total Trains", summariseExpression = "n()" ) pt $ defineCalculation (calculationName = "MinArrivalDelay", caption = "Min Arr. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |