rm(list=ls())
library(tidyverse)
library(nycflights13)
data(flights)
data(airlines)
data(airports)
data(weather)
#Question 1: Find all flights on January 1st
filter(flights, month == 1, day == 1)
#Question 2: Find arrival delay (arr_delay) more than 120 minutes and show arr_delay in the fourth column
filter(flights, arr_delay >= 120)
data <- data.frame(filter(flights, arr_delay >= 120))
library(dplyr)
data <- data %>% relocate(arr_delay, .before = dep_time)
head(data)
#Question 3: We need to find the longest arr_delay and its carrier, flight information. We need to think which function can rank data in descending order
data <- data %>% select (arr_delay, carrier)
data %>% arrange(desc(arr_delay))
#Question 4: Which carrier has the worst average arr_delay? its value? Use group_by, summarise/mutate and arrange