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.
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.
For this homework we will use the data sets provided by the nycflights13
package.
library(nycflights13)
library(tidyverse)
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
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.
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
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).
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.