Stat. 450: Quiz preparation

These question is related to the homework problem 5.6.7 Exercise 1.

For the flights data, in the nycflights13 package, answer the following questions:

library(nycflights13)
library(tidyverse)
  1. How many flights arrived on time (which includes the flights that arrived early)?

To answer this question we will look at the arr_delay to look at the flights that arrived on time.

Answer: 194,342

flights %>% select(arr_delay) %>%
  filter(arr_delay <= 0) %>%
  summarize( n=n() )
  1. What proportion of flights arrived on time?

To answer this question we will look at the arr_delay to look at the flights that arrived on time.

Answer: Approximately 60%.

flights %>% select(arr_delay) %>%
  summarize( arr_delay_mean = mean(arr_delay <= 0, na.rm = TRUE) )
  1. How many United flights arrived 30 or more minutes late?

Answer: The number of UA flights that arrived 30 or more minutes late was 8131.

flights %>% filter( carrier == "UA") %>%
  count(arr_delay >= 30)
  1. Which airline has the best on-time performance?

Answer: AS

flights %>% select(arr_delay, carrier) %>%
  group_by(carrier)  %>%
  summarize( n=n(), arr_delay_mean=mean(arr_delay <= 0, na.rm = TRUE) ) %>%
  arrange(desc(arr_delay_mean))
  1. Which airline has the worst on-time performance?

Answer: FL

flights %>% select(arr_delay, carrier) %>%
  group_by(carrier)  %>%
  summarize( n=n(), arr_delay_mean=mean(arr_delay <= 0, na.rm = TRUE) ) %>%
  arrange(arr_delay_mean)
LS0tCnRpdGxlOiAiU3RhdC4gNDUwIFF1aXogcHJlcGFyYXRpb24iCm91dHB1dDoKICB3b3JkX2RvY3VtZW50OiBkZWZhdWx0CiAgcGRmX2RvY3VtZW50OiBkZWZhdWx0CiAgaHRtbF9ub3RlYm9vazogZGVmYXVsdAotLS0KCioqU3RhdC4gNDUwOioqIFF1aXogcHJlcGFyYXRpb24KClRoZXNlIHF1ZXN0aW9uIGlzIHJlbGF0ZWQgdG8gdGhlIGhvbWV3b3JrIHByb2JsZW0gNS42LjcgRXhlcmNpc2UgMS4KCkZvciB0aGUgZmxpZ2h0cyBkYXRhLCBpbiB0aGUgbnljZmxpZ2h0czEzIHBhY2thZ2UsIGFuc3dlciB0aGUgZm9sbG93aW5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