Using the nycflights13 dataset, I want to find, using R, which flight was the latest in each month; in other words, the flight with the largest departure delay in each month.
The code I've used:
flights %>% group_by(flights$month) %>% summarize(largest_delay = max(flights$dep_delay, na.rm=TRUE))
this gives me a table of the months along with the the largest departure delay across the entire dataset, rather than the month-wise maximum:
> flights %>% group_by(flights$month) %>% summarize(largest_delay = max(flights$dep_delay, na.rm=TRUE))
# A tibble: 12 x 2
flights$month` largest_delay
<int> <dbl>
1 1 1301
2 2 1301
3 3 1301
4 4 1301
5 5 1301
6 6 1301
7 7 1301
8 8 1301
9 9 1301
10 10 1301
11 11 1301
12 12 1301
My question: how would I modify the above code such that it gives me the month-wise max? Also, how can I add in an additional column that contains the tailnum corresponding to that flight?