Skip to content

A foremost aviation industry player with a significant presence in New York City has launched an in-depth data analysis project focused on identifying trends in flight durations in air travel. This initiative aims to delve into a wealth of data related to flight schedules and operational patterns, with the objective of optimizing flight times and enhancing the overall travel experience for passengers. As the head data analyst, you have access to rich datasets, sourced from the 'nycflights2022' collection produced by the ModernDive team. These datasets include records of flights departing from major New York City airports, including JFK (John F. Kennedy International Airport), LGA (LaGuardia Airport), and EWR (Newark Liberty International Airport), during the second half of 2022. They offer a comprehensive view of flight operations, covering various aspects such as departure and arrival times, flight paths, and airline specifics:

  • flights2022-h2.csv contains information about each flight including
VariableDescription
carrierAirline carrier code
originOrigin airport (IATA code)
destDestination airport (IATA code)
air_timeDuration of the flight in air, in minutes
  • airlines.csv contains information about each airline:
VariableDescription
carrierAirline carrier code
nameFull name of the airline
  • airports.csv provides details of airports:
VariableDescription
faaFAA code of the airport
nameFull name of the airport
# Import required packages
library(dplyr)
library(readr)

# Load the data
flights <- read_csv("flights2022-h2.csv")
airlines <- read_csv("airlines.csv")
airports <- read_csv("airports.csv")

# Start your code here!
# Join flights, airlines, and airports dataframes
complex_join <- flights %>%
 left_join(airlines, by = "carrier") %>%
 rename(airline_name = name) %>%
 left_join(airports, by = c("dest" = "faa")) %>%
 rename(airport_name = name)

# Find flight duration (in hours)
transformed_data <- complex_join %>%
 mutate(flight_duration = air_time / 60)

# Find average flight duration and number of flights for each airline and airport
analysis_result <- transformed_data %>%
 group_by(airline_name, airport_name) %>%
 summarize(avg_flight_duration = mean(flight_duration, na.rm = TRUE), count = n()) %>%
 ungroup()
# From which airline and to which city do most flights from NYC go to?
frequent<-analysis_result%>%
arrange(desc(count))%>%
head(1)
# Which airline and to which airport has the longest average flight duration(in hours)from NYC?
longest<-analysis_result%>%
arrange(desc(avg_flight_duration))%>%
head(1)
#What is the least common destination airporting departing from JFK?
transformed_data%>%
 filter(origin=="JFK")%>%
 group_by(airport_name)%>%
 summarize(count=n())%>%
 arrange(count)
least<-"Eagle County Regional Airport"