2  In Class Exercise 1

Author

Yudum Paçin

Published

October 21, 2022

IN CLASS EXERCISE 1

Install necessary packages

install.packages("tidyverse")
install.packages("nycflights13")

Call necessary libraries

library(tidyverse)
library(nycflights13)

In this exercise, we will explore planes dataset in nycflights13 library . Planes, consists of construction information about 3,322 planes used for all flights departing NYC in 2013.

2.1 Most common planes

10 Most common models, manufacturers of the planes are,

planes %>% 
  group_by(model,manufacturer) %>%
  summarise(say=n()) %>%
  arrange(desc(say),10)
# A tibble: 147 × 3
# Groups:   model [127]
   model       manufacturer                    say
   <chr>       <chr>                         <int>
 1 737-7H4     BOEING                          361
 2 CL-600-2B19 BOMBARDIER INC                  162
 3 A320-232    AIRBUS                          129
 4 A320-232    AIRBUS INDUSTRIE                127
 5 CL-600-2D24 BOMBARDIER INC                  123
 6 737-824     BOEING                          122
 7 EMB-145LR   EMBRAER                         114
 8 737-3H4     BOEING                          105
 9 EMB-145XR   EMBRAER                         104
10 MD-88       MCDONNELL DOUGLAS AIRCRAFT CO   103
# … with 137 more rows

737-7H4 BOEING is the most common plane, Let’s have a look at this plane in detail

737-7H4 is a BOEING model only!, There is no other manufacturer. So, we can filter with “model” only.

planes %>% 
  filter(model=='737-7H4' & manufacturer!='BOEING') 
# A tibble: 0 × 9
# … with 9 variables: tailnum <chr>, year <int>, type <chr>,
#   manufacturer <chr>, model <chr>, engines <int>, seats <int>, speed <int>,
#   engine <chr>

2.2 In which years, BOEING 737-7H4 model is constructed and how many?

In, what years “737-7H4” is constructed, and how many?

planes %>% 
  filter(model=='737-7H4') %>%
  group_by(year) %>%
  summarise(say=n())
# A tibble: 16 × 2
    year   say
   <int> <int>
 1  1997     3
 2  1998    22
 3  1999    32
 4  2000    32
 5  2001    27
 6  2002    10
 7  2003    18
 8  2004    48
 9  2005    32
10  2006    33
11  2007    36
12  2008    22
13  2009    13
14  2010    11
15  2011    16
16    NA     6

Since 1997, 737-7H4 is constructed and used in NYC flights There are 6 planes having missing year values. In 2004, number of 737-7H4 planes is at the peak, after 2004 number of 737-7H4 planes are decreasing, but still it is the most common plane model in NYC flights.

2.3 Is seat number of BOEING 737-7H4 different from average number of seats?

all_seats = planes %>% 
  summarise(mean(seats),min(seats),max(seats),sd(seats))

common_model_seats = planes %>% 
  filter(model=='737-7H4') %>%
  group_by(model) %>%
  summarise(avg_seats=mean(seats),min(seats),max(seats))

all_seats
# A tibble: 1 × 4
  `mean(seats)` `min(seats)` `max(seats)` `sd(seats)`
          <dbl>        <int>        <int>       <dbl>
1          154.            2          450        73.7
common_model_seats
# A tibble: 1 × 4
  model   avg_seats `min(seats)` `max(seats)`
  <chr>       <dbl>        <int>        <int>
1 737-7H4       140          140          140

BOEING 737-7H4 has 140 seats, average number of seats of all planes is 154, so we can say, the model number of seat is near to the overall mean.