Loading the necessary packages
library(tidyverse)
library(lubridate)
library(knitr)
library(skimr)Importing the data set fullMiFlights2021.rds as michiganFlights
michiganFlights <- readRDS("C:/Users/sujith parsa/OneDrive/Desktop/STA_518/Activities/fullMiFlights2021.rds")
View(michiganFlights)michiganFlights is an object of type list and it has length of 5.
using the code to create explicit data tables in our global environment.
# Create tibbles in environment from list
list2env(michiganFlights, envir = .GlobalEnv)Exploratory Data Analysis
glimpse(airlines)
glimpse(airports)
glimpse(flights)
glimpse(planes)
glimpse(weather)
skim(flights)
skim(weather)The flights and planes data sets are connected through “tailnum” variable.
The flights and airports data sets are connected through “faa” variable.
The flights and weather data sets are connected through [“year”, “month”, “day”, “hour” , origin”] variables.
To draw the routes each plane flies from it’s origin to destination we need to combine flights and airports tables and origin, destination, longitude and latitude variables are required.
If we want to relate the departure delays with different weather characteristics we would need to combine the flights data set with the weathers data set and we would need the year, origin, month, day, hour, wind direction, wind speed, wind gust and precipitation variables are required.
Combining the flights and airlines data frames with left_join() to create a new data set called flightsCarriers.
flightscarriers <- left_join(flights, airlines)Calculate the average flight distance for each carrier using the full name of the carriers. Who had the longest flights on average? Who had the shortest?
flightscarriers %>% group_by(name) %>%
summarize(AvgDistance=mean(distance, na.rm=TRUE))%>%
arrange(desc(AvgDistance))Alaska Airlines Inc, had the longest flights on average and Endeavor Air Inc had the shortest flights on average.
# Combine the weather and flights data frames with left_join() to create a new data set called weatherFlights. How many rows does weatherFlights have?
weatherFlights <- left_join(weather, flights, by=c("origin" = "origin",
"year" = "year",
"month" = "month",
"day" = "day",
"hour" = "hour"))
weatherFlights %>% nrow()
# Combine the flights and weather data frames with left_join() to create a new data set called flightsWeather. How many rows does flightsWeather have?
flightsWeather <- left_join(flights,weather, by=c("origin" = "origin",
"year" = "year",
"month" = "month",
"day" = "day",
"hour" = "hour"))
flightsWeather %>% nrow()
# Combine the weather and flights data frames with full_join() to create a new data set called weatherFlightsFull. How many rows does weatherFlightsFull have?
weatherFlightsFull <- flights %>% full_join(weather,
by=c("origin" = "origin",
"year" = "year",
"month" = "month",
"day" = "day",
"hour" = "hour"))
weatherFlightsFull %>% nrow()
#Considering all of the data we have available, how many flights have missing wind speeds?
flightsWeather %>% pull(wind_speed) %>% is.na() %>% sum()
weatherFlightsFull %>% pull(wind_speed) %>% is.na() %>% sum() weatherFlights have 168159 observations (rows) flightsweather has 149445 observations (rows) 1526 flights had missing wind speeds weather flights full gives some extra rows.
Combine the weather and flights data frames with inner_join() to create a new data set called innerWeatherFlights. How many rows does innerWeatherFlights have?
innerWeatherFlights <- flights %>% inner_join(weather,
by=c("origin" , "year", "month", "day", "hour"))
innerWeatherFlights %>% nrow()What does the number of rows in innerWeatherFlights and weatherFlights tell us about the data set?
Since, innerWeatherFlights has many less rows than weather flights. This means some airports had hourly weather data but no flights departing during that hour.