library(tidyverse)
library(nycflights13)
2 Inclass Exercise-1
After installation step we have to call the packages :
First, we take a look at the data to see how many columns and rows we have, as well as what types of data we have :
glimpse(planes)
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…
In “plane” dataset we have information about each plane’s construction.
2.0.1 Number of plane counts by the seat for AIRBUS
%>%
planes filter(manufacturer == "AIRBUS INDUSTRIE") %>%
group_by(seats) %>%
summarise(count_of_planes = n()) %>%
arrange(desc(count_of_planes))
# A tibble: 7 × 2
seats count_of_planes
<int> <int>
1 200 127
2 179 124
3 182 94
4 145 26
5 199 25
6 379 3
7 375 1
2.0.2 For each manufacturer oldest, newest plane model and counts
%>%
planes group_by(manufacturer) %>%
summarise(min_model_year = min(year, na.rm = T), max_model_year = max(year, na.rm = T),distinct_plane_counts =n_distinct(tailnum)) %>%
arrange(manufacturer) %>%
print(n = Inf)
# A tibble: 35 × 4
manufacturer min_model_year max_model_year distinct_plane_…¹
<chr> <dbl> <dbl> <int>
1 AGUSTA SPA 2001 2001 1
2 AIRBUS 2002 2013 336
3 AIRBUS INDUSTRIE 1989 2013 400
4 AMERICAN AIRCRAFT INC Inf -Inf 2
5 AVIAT AIRCRAFT INC 2007 2007 1
6 AVIONS MARCEL DASSAULT 1986 1986 1
7 BARKER JACK L Inf -Inf 1
8 BEECH 1967 1972 2
9 BELL 1975 1994 2
10 BOEING 1965 2013 1630
11 BOMBARDIER INC 1998 2013 368
12 CANADAIR 1997 1998 9
13 CANADAIR LTD 1974 1974 1
14 CESSNA 1959 1983 9
15 CIRRUS DESIGN CORP 2007 2007 1
16 DEHAVILLAND 1959 1959 1
17 DOUGLAS 1956 1956 1
18 EMBRAER 1998 2013 299
19 FRIEDEMANN JON 2007 2007 1
20 GULFSTREAM AEROSPACE 1976 1992 2
21 HURLEY JAMES LARRY Inf -Inf 1
22 JOHN G HESS Inf -Inf 1
23 KILDALL GARY 1985 1985 1
24 LAMBERT RICHARD Inf -Inf 1
25 LEARJET INC Inf -Inf 1
26 LEBLANC GLENN T 1985 1985 1
27 MARZ BARRY 1993 1993 1
28 MCDONNELL DOUGLAS 1975 1998 120
29 MCDONNELL DOUGLAS AIRCRAFT CO 1987 1993 103
30 MCDONNELL DOUGLAS CORPORATION 1991 1992 14
31 PAIR MIKE E Inf -Inf 1
32 PIPER 1968 1980 5
33 ROBINSON HELICOPTER CO 2012 2012 1
34 SIKORSKY 1985 1985 1
35 STEWART MACO 1985 1985 2
# … with abbreviated variable name ¹distinct_plane_counts