Show the code
library(nycflights13)
library(tidyverse)
library(scales)DS 350 · Data Wrangling & Visualization
Spencer Payne
Using every flight that left New York City in 2013 (nycflights13), I answered two traveler questions: which NYC origin airport gives the best chance of arriving on time when flying Delta, and which destination airport is the worst for arrival delays.
Which origin airport is best to minimize my chances of a late arrival when I am using Delta Airlines?
# A tibble: 3 × 5
origin total_flights avg_arrival_delay median_arrival_delay percent_late_15
<chr> <int> <dbl> <dbl> <dbl>
1 JFK 20559 -2.38 -11 0.166
2 LGA 22804 3.93 -7 0.193
3 EWR 4295 8.78 -4 0.205


# A tibble: 1 × 5
origin total_flights avg_arrival_delay median_arrival_delay percent_late_15
<chr> <int> <dbl> <dbl> <dbl>
1 JFK 20559 -2.38 -11 0.166
The JFK airport has the best chance to minimize a late arrival while using Delta. On average Delta overestimates their arrival delay from JFK to anywhere so they let their passengers feel like they are getting in early. This doesn’t necessarily mean that they arrive faster but that they give a generous gap for their pilots to work with in getting from point A to point B.
Which destination airport is the worst airport for arrival delays? You decide on the metric for “worst.”
destination_summary <- delta_flights %>%
group_by(dest) %>%
summarize(total_flights = n(),
avg_arrival_delay = mean(arr_delay),
median_arrival_delay = median(arr_delay),
percent_late_15 = mean(late_15),
.groups = "drop") %>%
filter(total_flights >= 30) %>%
arrange(desc(percent_late_15))
destination_summary# A tibble: 28 × 5
dest total_flights avg_arrival_delay median_arrival_delay percent_late_15
<chr> <int> <dbl> <dbl> <dbl>
1 SAT 302 8.08 -12 0.255
2 DEN 1036 6.01 -5 0.248
3 PDX 457 4.25 -7 0.232
4 PIT 247 5.91 -12 0.227
5 MIA 2902 2.27 -9 0.215
6 FLL 2876 2.32 -7 0.212
7 PWM 233 1.14 -13 0.210
8 ATL 10452 7.42 -4 0.202
9 PBI 1450 2.06 -7 0.190
10 AUS 352 1.41 -12 0.190
# ℹ 18 more rows

# A tibble: 1 × 5
dest total_flights avg_arrival_delay median_arrival_delay percent_late_15
<chr> <int> <dbl> <dbl> <dbl>
1 SAT 302 8.08 -12 0.255
The worst airport for arrival delays would be SAT. This is because the average arrival delay is the highest out of all of the other airports, the median delay is one of the top 3 and the percent of flights that get delayed is the highest out of all of them.