2  In Class Assignment1

Published

October 19, 2022

First I installed the packages with the below commands;

install.packages(“tidyverse”) install.packages(“nycflights13”)

Let’s call the packages :

library(tidyverse)
── 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)

We can see there are 3,222 rows and 9 columns. We can see the columns names and data type

planes %>% glimpse()
Rows: 3,322
Columns: 9
$ tailnum      <chr> "N10156", "N102UW", "N103US", "N104UW", "N10575", "N105UW…
$ year         <int> 2004, 1998, 1999, 1999, 2002, 1999, 1999, 1999, 1999, 199…
$ type         <chr> "Fixed wing multi engine", "Fixed wing multi engine", "Fi…
$ manufacturer <chr> "EMBRAER", "AIRBUS INDUSTRIE", "AIRBUS INDUSTRIE", "AIRBU…
$ model        <chr> "EMB-145XR", "A320-214", "A320-214", "A320-214", "EMB-145…
$ engines      <int> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, …
$ seats        <int> 55, 182, 182, 182, 55, 182, 182, 182, 182, 182, 55, 55, 5…
$ speed        <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
$ engine       <chr> "Turbo-fan", "Turbo-fan", "Turbo-fan", "Turbo-fan", "Turb…

Let’s see the number of planes belonging to the manufacturers.

planes %>% 
  group_by(manufacturer) %>% 
  summarise(count=n()) %>% 
  arrange(manufacturer) %>% 
  print(n=Inf)
# A tibble: 35 × 2
   manufacturer                  count
   <chr>                         <int>
 1 AGUSTA SPA                        1
 2 AIRBUS                          336
 3 AIRBUS INDUSTRIE                400
 4 AMERICAN AIRCRAFT INC             2
 5 AVIAT AIRCRAFT INC                1
 6 AVIONS MARCEL DASSAULT            1
 7 BARKER JACK L                     1
 8 BEECH                             2
 9 BELL                              2
10 BOEING                         1630
11 BOMBARDIER INC                  368
12 CANADAIR                          9
13 CANADAIR LTD                      1
14 CESSNA                            9
15 CIRRUS DESIGN CORP                1
16 DEHAVILLAND                       1
17 DOUGLAS                           1
18 EMBRAER                         299
19 FRIEDEMANN JON                    1
20 GULFSTREAM AEROSPACE              2
21 HURLEY JAMES LARRY                1
22 JOHN G HESS                       1
23 KILDALL GARY                      1
24 LAMBERT RICHARD                   1
25 LEARJET INC                       1
26 LEBLANC GLENN T                   1
27 MARZ BARRY                        1
28 MCDONNELL DOUGLAS               120
29 MCDONNELL DOUGLAS AIRCRAFT CO   103
30 MCDONNELL DOUGLAS CORPORATION    14
31 PAIR MIKE E                       1
32 PIPER                             5
33 ROBINSON HELICOPTER CO            1
34 SIKORSKY                          1
35 STEWART MACO                      2

Let’s get the number of plane numbers for each year

planes %>% 
  group_by(year) %>% 
  summarise(count=n()) %>% 
  arrange(year) %>% 
  print(n=Inf)
# A tibble: 47 × 2
    year count
   <int> <int>
 1  1956     1
 2  1959     2
 3  1963     2
 4  1965     1
 5  1967     1
 6  1968     1
 7  1972     1
 8  1973     1
 9  1974     1
10  1975     3
11  1976     3
12  1977     2
13  1978     2
14  1979     4
15  1980     4
16  1983     1
17  1984     5
18  1985    23
19  1986    17
20  1987    40
21  1988    75
22  1989    60
23  1990    90
24  1991   108
25  1992   109
26  1993    59
27  1994    48
28  1995    54
29  1996    55
30  1997    74
31  1998   174
32  1999   206
33  2000   244
34  2001   284
35  2002   212
36  2003   150
37  2004   192
38  2005   162
39  2006   126
40  2007   123
41  2008   147
42  2009    84
43  2010    48
44  2011    66
45  2012    95
46  2013    92
47    NA    70