How do I get the months with the highest average departure time for each airline from this dataset?

"For each airlines find the month where the average departure time is the highest in the year." I have the table built with the airline name, month, and average departure time but I don't know how to select out what I want.

library("nycflights13")
library(tidyverse)
dffl= flights
dfa=airlines
dfall <- merge(dfa, dffl, by ="carrier")

dfall %>%
  group_by(name, month) %>%
  summarise(mean_dt= mean(dep_time)) %>%
  arrange(desc(mean_dt))

Ive tried adding select(max(mean_dt)) but then it says mean_dt not found.

I believe I figured it out.

library("nycflights13")
library(tidyverse)
library(dplyr)
dffl= flights
dfa=airlines
dfall <- merge(dfa, dffl, by ="carrier")

dfall %>%
  group_by(name, month) %>%
  summarise(mean_dt= mean(dep_time)) %>%
  arrange(desc(mean_dt))%>%
  slice_max(mean_dt)

You want to make a small adjustment to your code.

summarise(mean_dt= mean(dep_time)) %>%

This line is giving you some trouble and is returning NA for any cancelled flight. So, if Delta cancels a flight in February, you have no February Delta data.

summarise(mean_dt= mean(dep_time, rm.na=TRUE)) %>%

Adding rm.na=TRUE will filter out all the NA values in dep_time.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.