-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathassignment_tidy.Rmd
More file actions
62 lines (45 loc) · 1.89 KB
/
Copy pathassignment_tidy.Rmd
File metadata and controls
62 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: "Assignment_tidy"
author: "Alvaro Bueno"
date: "9/30/2017"
output: html_document
---
## Assignment, tidying up table
```{r setup, include=FALSE}
#import libraries
library('tidyr')
library('dplyr')
```
## opening file and performin initial tidy functions
```{r read}
#open
dat = read.csv("https://raw.githubusercontent.com/delagroove/dataScience/master/flightsinfo.csv", header = ,na.strings=c("","NA"))
## gather the table by city
res <- gather(dat, "los.angeles", "phoenix", "san.diego", "san.francisco", "seattle", key="city", value="count")
## remove Na values on count
res <- drop_na(res,count)
#rename columns
colnames(res)[1] <- "airline"
colnames(res)[2] <- "status"
#fill the empty values for airline with the value from above.
res <- fill(res, "airline")
```
## Now with data complete, we can do our calculations
```{r calc}
## get the total count of flights to a city
sums <- group_by(res, city, airline) %>% summarise(sum(count))
#duplicate a row in between to use the sum for the calculation
sums <- sums[rep(seq_len(nrow(sums)), each=2),]
#initialize new column to store ratio
res$ratio = 0
## save the ratio of flights on time/delayed vs total flights to that city.
for(the_city in levels(as.factor(res$city))){
for(the_airline in levels(res$airline)){
res[which(res$city==the_city,res$airline==the_airline),]$ratio <- res[which(res$city==the_city,res$airline==the_airline),]$count/sums[which(sums$city==the_city,sums$airline==the_airline),]$`sum(count)`
}
}
(res)
```
## conclusion
We can assess here that Alaska has more percentage of flights on time than AM WEST, with pronounced differences in the flights to san francisco and seattle. The difference is not significant at all in Phoenix, where AM West operation is quite big.
A recommendation for AM West would be to upgrade operations in San Francisco and Seattle specially where their operations are constantly delayed.