2  In Class Exercise 1

Published

October 19, 2022

library(tidyverse)
library(nycflights13)

2.1 The number of planes according to manufacturer brands

We are talking about NewYork. It is acceptable that BOEING has the highest number of planes, considering that BOEING is an American manufacturer.

planes %>% 
  group_by(manufacturer)%>%
  summarise(count=n()) %>% 
  arrange(desc(count))
# A tibble: 35 × 2
   manufacturer                  count
   <chr>                         <int>
 1 BOEING                         1630
 2 AIRBUS INDUSTRIE                400
 3 BOMBARDIER INC                  368
 4 AIRBUS                          336
 5 EMBRAER                         299
 6 MCDONNELL DOUGLAS               120
 7 MCDONNELL DOUGLAS AIRCRAFT CO   103
 8 MCDONNELL DOUGLAS CORPORATION    14
 9 CANADAIR                          9
10 CESSNA                            9
# … with 25 more rows

2.2 Investigating planes that has more than 2 engines; sorted according to the year.

Big Planes, big engines….

planes %>%
  filter(engines>2)%>%
  arrange(year,desc(year))
# A tibble: 7 × 9
  tailnum  year type                    manuf…¹ model engines seats speed engine
  <chr>   <int> <chr>                   <chr>   <chr>   <int> <int> <int> <chr> 
1 N381AA   1956 Fixed wing multi engine DOUGLAS DC-7…       4   102   232 Recip…
2 N840MQ   1974 Fixed wing multi engine CANADA… CF-5D       4     2    NA Turbo…
3 N905FJ   1986 Fixed wing multi engine AVIONS… MYST…       3    12    NA Turbo…
4 N670US   1990 Fixed wing multi engine BOEING  747-…       4   450    NA Turbo…
5 N854NW   2004 Fixed wing multi engine AIRBUS  A330…       3   379    NA Turbo…
6 N856NW   2004 Fixed wing multi engine AIRBUS  A330…       3   379    NA Turbo…
7 N281AT     NA Fixed wing multi engine AIRBUS… A340…       4   375    NA Turbo…
# … with abbreviated variable name ¹​manufacturer

2.3 BONUS - Quick Guys !

Total number of flights that had delayed departure but arrived before scheduled time grouped by the carrier. United Airlines has the most number of flights in this category.

flights%>%
  filter(dep_delay>0 & arr_delay<0)%>%
  group_by(carrier)%>%
  summarize(count=n())%>%
  arrange(desc(count))
# A tibble: 16 × 2
   carrier count
   <chr>   <int>
 1 UA      10031
 2 DL       4815
 3 B6       4598
 4 EV       3511
 5 AA       3305
 6 WN       2135
 7 9E       1830
 8 VX        967
 9 US        931
10 MQ        925
11 FL        233
12 AS         98
13 F9         76
14 YV         33
15 HA         32
16 OO          1