library(RCurl)
## Loading required package: bitops
library(tidyr)
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:RCurl':
## 
##     complete
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
x<-getURL("https://raw.githubusercontent.com/Jagdish16/jagdish_r_repo/master/DATA607/Week5/airlinedelays.csv")
airlinedata<-read.csv(text=x,header=TRUE)
airlinedata
##   Airline ArrivalStatus Los.Angeles Phoenix San.Diego San.Francisco
## 1  ALASKA       on time         497     221       212           503
## 2  ALASKA       delayed          62      12        20           102
## 3  AMWEST       on time         694    4840       383           320
## 4  AMWEST       delayed         117     415        65           129
##   Seattle
## 1    1841
## 2     305
## 3     201
## 4      61
airline.delays<-gather(airlinedata, key="Destination", value=NumberofFlights, 3:7)
colnames(airline.delays)<-c("Airline", "ArrivalStatus", "Destination", "NumberofFlights")
#airline.delays
airline.delays$Airline<-as.character(airline.delays$Airline)
airline.delays$Destination<-as.character(airline.delays$Destination)
airline.delays$ArrivalStatus<-as.character(airline.delays$ArrivalStatus)
alaska.ontime<-filter(airline.delays, Airline=="ALASKA",ArrivalStatus=="on time")
alaska.delayed<-filter(airline.delays, Airline=="ALASKA",ArrivalStatus=="delayed")
amwest.ontime<-filter(airline.delays, Airline=="AMWEST",ArrivalStatus=="on time")
amwest.delayed<-filter(airline.delays, Airline=="AMWEST",ArrivalStatus=="delayed")
#alaska.info<-alaska %>% group_by(ArrivalStatus) %>% mutate(sum(NumberofFlights))
alaska.delayed.prop<-sum(alaska.delayed$NumberofFlights)/(sum(alaska.ontime$NumberofFlights)+sum(alaska.delayed$NumberofFlights))
alaska.delayed.prop
## [1] 0.1327152
amwest.delayed.prop<-sum(amwest.delayed$NumberofFlights)/(sum(amwest.ontime$NumberofFlights)+sum(amwest.delayed$NumberofFlights))
amwest.delayed.prop
## [1] 0.1089273
cat("The analysis shows that a higher proportion of flights across all destinations were delayed for Alaska Airlines as compared to AMWest.")
## The analysis shows that a higher proportion of flights across all destinations were delayed for Alaska Airlines as compared to AMWest.
#air.info<-airline.delays %>% group_by(Airline,ArrivalStatus) %>% mutate(sum(NumberofFlights))
#air.info