Submission Details

Due date: the homework is due before class on Thursday.

Submission process: submit both the R Markdown file and the corresponding html file on canvas. Please submit both the .Rmd and the .html files separately and do not zip the two files together.


NYC flights data

  1. Download the RMarkdown file with these homework instructions to use as a template for your work. Make sure to replace “Your Name” in the YAML with your name.

  2. For this homework we will use the data sets provided by the nycflights13 package.

library(nycflights13)
library(tidyverse)
  1. What are the ten most common destinations for flights from NYC airports in 2013? Make a table that lists these in descending order and shows the number of fligts heading to each airport.
flights %>%
  count(dest) %>%
  arrange(desc(n)) %>%
  slice(1:10)
## # A tibble: 10 x 2
##    dest      n
##    <chr> <int>
##  1 ORD   17283
##  2 ATL   17215
##  3 LAX   16174
##  4 BOS   15508
##  5 MCO   14082
##  6 CLT   14064
##  7 SFO   13331
##  8 FLL   12055
##  9 MIA   11728
## 10 DCA    9705
  1. What was the mean temperature at the origin airport on the day with the highest departure delay? Your answer should include the name of origin airport, the date with the highest departure delay, and the mean temperature on that day.
flights %>%
  arrange(desc(dep_delay)) %>%
  slice(1) %>%
  select(dep_delay, month, day, origin)
## # A tibble: 1 x 4
##   dep_delay month   day origin
##       <dbl> <int> <int> <chr> 
## 1      1301     1     9 JFK

The highest departure delay of 1301 minutes (approx 21.7 hours) was on a flight departing from JFK on Jan 9.

weather %>%
  filter(month == 1, day == 9, origin == "JFK") %>%
  summarise(mean_temp = mean(temp))
## # A tibble: 1 x 1
##   mean_temp
##       <dbl>
## 1      42.7

The average temperature on this day was 42.66 F.

  1. Find the flight with the longest air time.
    (a) How long is this flight?
    (b) What city did it fly to?
    (c) How many seats does the plane that flew this flight have?
flights %>%
  arrange(desc(air_time)) %>%
  slice(1) %>%
  select(air_time, dest, tailnum) %>%
  left_join(planes, by = "tailnum") %>%
  select(air_time, dest, tailnum, seats)
## # A tibble: 1 x 4
##   air_time dest  tailnum seats
##      <dbl> <chr> <chr>   <int>
## 1      695 HNL   N77066    292
  1. The flight time is 695 minutes (11.58 hours).
  2. Flight was to Honolulu.
  3. Plane that flew this flight has 292 seats.
  1. Consider only flights that have non-missing arrival delay information. Your answer should include the name of the carrier in addition to the carrier code and the values asked. (a) Which carrier had the highest mean arrival delay? (b) Which carrier had the lowest mean arrival delay? Make sure that your answer includes the name of the carrier and the calculated mean delay.
flights %>%
  filter(!is.na(arr_delay)) %>%
  group_by(carrier) %>%
  summarise(mean_arr_delay = mean(arr_delay)) %>%
  arrange(desc(mean_arr_delay)) %>%
  left_join(airlines, by = "carrier") %>%
  slice(c(1, n()))
## # A tibble: 2 x 3
##   carrier mean_arr_delay name                  
##   <chr>            <dbl> <chr>                 
## 1 F9               21.9  Frontier Airlines Inc.
## 2 AS               -9.93 Alaska Airlines Inc.

Highest mean arrival delay was on Frontier Airlines with 21.9 minutes, and lowest mean was on Alaska Airlines with -9.93 minutes (which means 9.93 minutes early on average).

  1. Which airlines have the most flights departing from NYC airports in 2013? Make a table that lists these in descending order of frequency and shows the number of flights for each airline. In your narrative mention the names of the airlines as well.
    Hint: You can use the airlines dataset to look up the airline name based on carrier code.*
flights %>%
  count(carrier) %>%
  arrange(desc(n)) %>%
  left_join(airlines, by = "carrier")
## # A tibble: 16 x 3
##    carrier     n name                       
##    <chr>   <int> <chr>                      
##  1 UA      58665 United Air Lines Inc.      
##  2 B6      54635 JetBlue Airways            
##  3 EV      54173 ExpressJet Airlines Inc.   
##  4 DL      48110 Delta Air Lines Inc.       
##  5 AA      32729 American Airlines Inc.     
##  6 MQ      26397 Envoy Air                  
##  7 US      20536 US Airways Inc.            
##  8 9E      18460 Endeavor Air Inc.          
##  9 WN      12275 Southwest Airlines Co.     
## 10 VX       5162 Virgin America             
## 11 FL       3260 AirTran Airways Corporation
## 12 AS        714 Alaska Airlines Inc.       
## 13 F9        685 Frontier Airlines Inc.     
## 14 YV        601 Mesa Airlines Inc.         
## 15 HA        342 Hawaiian Airlines Inc.     
## 16 OO         32 SkyWest Airlines Inc.

The carrier with the highest number of flights departing from NYC airports in 2013 is United Airlines, followed by JetBlue Airways and ExpressJet Airlines.