library(bitops)
library(RCurl)
library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1 v purrr 0.3.2
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 0.8.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x tidyr::complete() masks RCurl::complete()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
file_url <- getURL("https://raw.githubusercontent.com/jey1987/DATA607/master/Week5_Assignment/Tidy_Input_Airlines_1.csv")
input_data <- data.frame(read.csv(text=file_url, header = TRUE),stringsAsFactors =FALSE)
You can also embed plots, for example:
input_data <- na.omit(input_data)
input_data[2,1] <- as.character(input_data[1,1])
input_data[4,1] <- as.character(input_data[3,1])
input_data[,1] <- str_replace_all(input_data[,1], c(" " = "_" , "," = "" ))
names(input_data)[1] <- paste("Airline")
names(input_data)[2] <- paste("Status")
input_data <- data.frame(gather(input_data, "destination","n",3:7 ),stringsAsFactors = FALSE)
input_data
prep_data <- input_data %>%
arrange(Airline,destination) %>%
group_by(Airline,destination)%>%
mutate(Total_flights_Per_city = sum(n)) %>%
mutate(on_time_delay_pct = (n/Total_flights_Per_city)*100) %>%
filter(Status == "on time")
prep_data
per_city_perf <- prep_data %>%
select(destination,Airline,on_time_delay_pct) %>%
spread(key = Airline,value = on_time_delay_pct) %>%
mutate(diff_pct = ALASKA - AM_WEST) %>%
mutate(reliable_airline = if(diff_pct > 0) "ALASKA" else "AM_WEST")
per_city_perf
overall_perf <- prep_data %>%
group_by(Airline) %>%
summarize(overall_pct = mean(on_time_delay_pct))
overall_perf
While comparing the two ratings ALASKA airlines is proven to be the most reliable airline but the number of flights plays a major role in determining the most reliable airline. Eventhough ALASKA has operated the flights successfully on major occasion the number of flights run by AM_WEST is more.