I'm trying to get the carrier with the max value of flights during the summer months
max_flights_all_c<-nycflights13::flights %>%
group_by(carrier,month)%>%
filter(month==6 | month==7 | month==8 | month==9)%>%
summarise(n=n())
Now I'm getting;
carrier month n
9E 7 1494
9E 8 1456
9E 9 1540
AA 6 2757
AA 7 2882
AA 8 2856
AA 9 2614
AS 6 60
AS 7 62
AS 8 62
AS 9 60
B6 6 4622
B6 7 4984
but want to obtain only the max value of n for month each month.
After the summarise
step, we group by 'month' and get the max
row of 'n' with slice
.
max_flights_all_c <- nycflights13::flights %>%
group_by(carrier,month)%>%
filter(month %in% 6:9) %>%
summarise(n = n()) %>%
group_by(month) %>%
slice(which.max(n))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With