Skip to content

Instantly share code, notes, and snippets.

@dggoldst
Created December 13, 2014 22:51
Show Gist options
  • Save dggoldst/24ad5432935015625ed4 to your computer and use it in GitHub Desktop.
Save dggoldst/24ad5432935015625ed4 to your computer and use it in GitHub Desktop.
library(dplyr)
library(xtable)
setwd("C:/Dropbox/Projects/20141211_Which_Airline_Loyalty")
load(file="2013flights.Rdata")
ldf = df %>%
group_by(origin_market_id,carrier) %>%
summarize(Departures = length(delay))
L_CITY_MARKET_ID <- read.csv("C:/Dropbox/Projects/20141211_Which_Airline_Loyalty/L_CITY_MARKET_ID.csv")
names(L_CITY_MARKET_ID)=c("origin_market_id","Market")
ldf=left_join(ldf,L_CITY_MARKET_ID)
L_CARRIER_HISTORY <- read.csv("C:/Dropbox/Projects/20141211_Which_Airline_Loyalty/L_CARRIER_HISTORY.csv")
L_CARRIER_HISTORY=L_CARRIER_HISTORY %>%
mutate(nc=nchar(as.character(Description)),
ss=substring(as.character(Description),nc-3,nc),
keep=ss==" - )",
bettername=substring(as.character(Description),1,nc-10)) %>%
filter(keep) %>%
select(Code,bettername)
names(L_CARRIER_HISTORY)=c("Code","Airline")
ldf=left_join(ldf,L_CARRIER_HISTORY)
ldf=ldf %>%
arrange(Market,-Departures)
ldf=ldf[,c('Market','Airline','Code','Departures')]
ldf$Departures=as.character(ldf$Departures)
output=xtable(ldf)
print(output, type='html', file="departure_count.html",
include.rownames=FALSE,
include.colnames=FALSE,
only.contents=TRUE,
html.table.attributes='id="example" class="display" cellspacing="0" width="100%"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment