2  Inclass1

Published

October 19, 2022

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.2.2
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6      ✔ purrr   0.3.5 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.1 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(nycflights13)
library(lubridate)

Attaching package: 'lubridate'

The following objects are masked from 'package:base':

    date, intersect, setdiff, union
library(dplyr)

2.0.1 Distribution of planes by year of manufacture and their manufacturers

First I find the range of production years to know where to start and where to end. Also to avoid NA I use is.finite function while finding max and min numbers.

max(planes$year[is.finite(planes$year)])
[1] 2013
min(planes$year[is.finite(planes$year)])
[1] 1956
planes %>% group_by(year = cut(year,breaks=c(1950,1955,1960,1965,1970,1975,1980,1985,1990,1995,2000,2005,2010,2015),include.lowest = TRUE)) %>% summarise("plane count" = n()) 
# A tibble: 13 × 2
   year        `plane count`
   <fct>               <int>
 1 (1955,1960]             3
 2 (1960,1965]             3
 3 (1965,1970]             2
 4 (1970,1975]             6
 5 (1975,1980]            15
 6 (1980,1985]            29
 7 (1985,1990]           282
 8 (1990,1995]           378
 9 (1995,2000]           753
10 (2000,2005]          1000
11 (2005,2010]           528
12 (2010,2015]           253
13 <NA>                   70
planes %>% filter(year > 1955 & year <= 1960) %>% count(manufacturer)
# A tibble: 3 × 2
  manufacturer     n
  <chr>        <int>
1 CESSNA           1
2 DEHAVILLAND      1
3 DOUGLAS          1
planes %>% filter(year > 1960 & year <= 1965) %>% count(manufacturer)
# A tibble: 2 × 2
  manufacturer     n
  <chr>        <int>
1 BOEING           1
2 CESSNA           2
planes %>% filter(year > 1965 & year <= 1970) %>% count(manufacturer)
# A tibble: 2 × 2
  manufacturer     n
  <chr>        <int>
1 BEECH            1
2 PIPER            1
planes %>% filter(year > 1970 & year <= 1975) %>% count(manufacturer)
# A tibble: 5 × 2
  manufacturer          n
  <chr>             <int>
1 BEECH                 1
2 BELL                  1
3 CANADAIR LTD          1
4 CESSNA                2
5 MCDONNELL DOUGLAS     1
planes %>% filter(year > 1975 & year <= 1980) %>% count(manufacturer)
# A tibble: 4 × 2
  manufacturer             n
  <chr>                <int>
1 CESSNA                   3
2 GULFSTREAM AEROSPACE     1
3 MCDONNELL DOUGLAS        7
4 PIPER                    4
planes %>% filter(year > 1980 & year <= 1985) %>% count(manufacturer)
# A tibble: 6 × 2
  manufacturer        n
  <chr>           <int>
1 BOEING             24
2 CESSNA              1
3 KILDALL GARY        1
4 LEBLANC GLENN T     1
5 SIKORSKY            1
6 STEWART MACO        1
planes %>% filter(year > 1985 & year <= 1990) %>% count(manufacturer)
# A tibble: 5 × 2
  manufacturer                      n
  <chr>                         <int>
1 AIRBUS INDUSTRIE                 13
2 AVIONS MARCEL DASSAULT            1
3 BOEING                          150
4 MCDONNELL DOUGLAS                51
5 MCDONNELL DOUGLAS AIRCRAFT CO    67
planes %>% filter(year > 1990 & year <= 1995) %>% count(manufacturer)
# A tibble: 8 × 2
  manufacturer                      n
  <chr>                         <int>
1 AIRBUS INDUSTRIE                 65
2 BELL                              1
3 BOEING                          222
4 GULFSTREAM AEROSPACE              1
5 MARZ BARRY                        1
6 MCDONNELL DOUGLAS                38
7 MCDONNELL DOUGLAS AIRCRAFT CO    36
8 MCDONNELL DOUGLAS CORPORATION    14
planes %>% filter(year > 1995 & year <= 2000) %>% count(manufacturer)
# A tibble: 6 × 2
  manufacturer          n
  <chr>             <int>
1 AIRBUS INDUSTRIE    212
2 BOEING              444
3 BOMBARDIER INC       16
4 CANADAIR              9
5 EMBRAER              53
6 MCDONNELL DOUGLAS    19
planes %>% filter(year > 2000 & year <= 2005) %>% count(manufacturer)
# A tibble: 6 × 2
  manufacturer         n
  <chr>            <int>
1 AGUSTA SPA           1
2 AIRBUS             123
3 AIRBUS INDUSTRIE    98
4 BOEING             370
5 BOMBARDIER INC     246
6 EMBRAER            162
planes %>% filter(year > 2005 & year <= 2010) %>% count(manufacturer)
# A tibble: 7 × 2
  manufacturer           n
  <chr>              <int>
1 AIRBUS               115
2 AVIAT AIRCRAFT INC     1
3 BOEING               258
4 BOMBARDIER INC        90
5 CIRRUS DESIGN CORP     1
6 EMBRAER               62
7 FRIEDEMANN JON         1
planes %>% filter(year > 2010 & year <= 2015) %>% count(manufacturer)
# A tibble: 6 × 2
  manufacturer               n
  <chr>                  <int>
1 AIRBUS                    90
2 AIRBUS INDUSTRIE           2
3 BOEING                   134
4 BOMBARDIER INC            10
5 EMBRAER                   16
6 ROBINSON HELICOPTER CO     1

2.0.2 Total capacity of manufacturers

I add all aircrafts from the same manufacturer to find total capacity of that manufacturer’s planes.

planes %>% group_by(manufacturer) %>% summarize("seats in total"=sum(seats)) %>% print(n = 35) 
# A tibble: 35 × 2
   manufacturer                  `seats in total`
   <chr>                                    <int>
 1 AGUSTA SPA                                   8
 2 AIRBUS                                   74324
 3 AIRBUS INDUSTRIE                         74961
 4 AMERICAN AIRCRAFT INC                        4
 5 AVIAT AIRCRAFT INC                           2
 6 AVIONS MARCEL DASSAULT                      12
 7 BARKER JACK L                                2
 8 BEECH                                       19
 9 BELL                                        16
10 BOEING                                  285556
11 BOMBARDIER INC                           27235
12 CANADAIR                                   495
13 CANADAIR LTD                                 2
14 CESSNA                                      48
15 CIRRUS DESIGN CORP                           4
16 DEHAVILLAND                                 16
17 DOUGLAS                                    102
18 EMBRAER                                  13645
19 FRIEDEMANN JON                               2
20 GULFSTREAM AEROSPACE                        44
21 HURLEY JAMES LARRY                           2
22 JOHN G HESS                                  2
23 KILDALL GARY                                 2
24 LAMBERT RICHARD                              2
25 LEARJET INC                                 11
26 LEBLANC GLENN T                              2
27 MARZ BARRY                                   2
28 MCDONNELL DOUGLAS                        19446
29 MCDONNELL DOUGLAS AIRCRAFT CO            14626
30 MCDONNELL DOUGLAS CORPORATION             1988
31 PAIR MIKE E                                  2
32 PIPER                                       34
33 ROBINSON HELICOPTER CO                       5
34 SIKORSKY                                    14
35 STEWART MACO                                 4