2  In Class Assignment-1

Using nycflights13 package I have prepared the following analyses.

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)

2.1 Analysis-1 Number of tailnumbers per grouped number of seats.

planes %>% 
  mutate(seat_bracket=case_when(seats<=100 ~ "(0-100]", seats<=200 ~"(100-200]",seats<=300 ~"(200-300]", seats<=400 ~"(300-400]",TRUE ~ "(400-HI]")) %>% 
  group_by(seat_bracket) %>%
  summarise(count=n()) %>% 
  print(n=Inf)
# A tibble: 5 × 2
  seat_bracket count
  <chr>        <int>
1 (0-100]        820
2 (100-200]     2207
3 (200-300]       98
4 (300-400]      196
5 (400-HI]         1


2.2 Analysis-2 Average, min and max speed with respect to type, engine and number of engines.

First, we check the distinct values of speed column.

planes %>%
  group_by(speed) %>%
  summarise(count=n()) %>%
  arrange(desc(speed)) %>%
  print(n=Inf)
# A tibble: 14 × 2
   speed count
   <int> <int>
 1   432     8
 2   232     1
 3   202     1
 4   167     1
 5   162     2
 6   127     1
 7   126     1
 8   112     1
 9   108     1
10   107     1
11   105     2
12    95     1
13    90     2
14    NA  3299

We see that most of the speed data is non-existent. With the remaining data here is the table for average, min and max of speed by type, engine and number of engines.

options(dplyr.summarise.inform=FALSE)
planes %>%
  filter(!is.na(speed)) %>%
  group_by(type,engine,engines) %>%
  summarise(avg_speed=round(mean(speed),2),min_speed=min(speed),max_speed=max(speed)) %>%
  arrange(type,engine,engines) %>%
  print(n=Inf)
# A tibble: 7 × 6
# Groups:   type, engine [6]
  type                     engine        engines avg_speed min_speed max_speed
  <chr>                    <chr>           <int>     <dbl>     <int>     <int>
1 Fixed wing multi engine  Reciprocating       2      145.        90       167
2 Fixed wing multi engine  Reciprocating       4      232        232       232
3 Fixed wing multi engine  Turbo-jet           2      432        432       432
4 Fixed wing multi engine  Turbo-prop          2      202        202       202
5 Fixed wing single engine 4 Cycle             1      108        108       108
6 Fixed wing single engine Reciprocating       1      108.        90       127
7 Rotorcraft               Turbo-shaft         1      112        112       112