As already discussed in the previous chapters, with the help of the microbenchmark
package, we can run any number of different functions for a specified number of times on the same machine to get some reproducible results on the performance.
To this end, we have to define the functions that we want to benchmark first. These were compiled from the preceding examples:
> AGGR1 <- function() aggregate(hflights$Diverted, + by = list(hflights$DayOfWeek), FUN = mean) > AGGR2 <- function() with(hflights, aggregate(Diverted, + by = list(DayOfWeek), FUN = mean)) > AGGR3 <- function() aggregate(Diverted ~ DayOfWeek, + data = hflights, FUN = mean) > TAPPLY <- function() tapply(X = hflights$Diverted, + INDEX = hflights$DayOfWeek, FUN = mean) > PLYR1 <- function() ddply(hflights, .(DayOfWeek), + function(x) mean(x$Diverted)) > PLYR2 <- function() ddply(hflights, .(DayOfWeek), summarise, + Diverted = mean(Diverted...