if (require("data.table")) {
# If you start with a data table, you end up with a data table
data("hflights", package = "hflights")
hflights <- as.data.table(hflights)
filter(hflights, Month == 1, DayofMonth == 1, Dest == "DFW")
head(select(hflights, Year:DayOfWeek))
summarise(hflights, delay = mean(ArrDelay, na.rm = TRUE), n = length(ArrDelay))
head(mutate(hflights, gained = ArrDelay - DepDelay))
head(arrange(hflights, Dest, desc(ArrDelay)))
# If you start with a tbl, you end up with a tbl
hflights2 <- as.tbl(hflights)
filter(hflights2, Month == 1, DayofMonth == 1, Dest == "DFW")
head(select(hflights2, Year:DayOfWeek))
summarise(hflights2, delay = mean(ArrDelay, na.rm = TRUE), n = length(ArrDelay))
head(mutate(hflights2, gained = ArrDelay - DepDelay))
head(arrange(hflights2, Dest, desc(ArrDelay)))
}
Run the code above in your browser using DataLab