Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update transform_solutions.Rmd #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions transform_solutions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,8 @@ arrange(flights, dep_delay)

### 3. Sort flights to find the fastest flights.
```{r}
# Note - this is a bit tricky since the time stamps are just encoded as integers
# so if a flight left at midnight (i.e. dep_time=2400) and arrived at 00:54 (arr_time=54),
# it's hard to just do arr_time - dep_time to get the travel time (you get back -2346, which doesn't make sense).
# Taking absolute values doesn't help either.
# A workaround solution is just to add 2400 if the travel time is ever negative.
# A better solution is to properly encode the times as timestamps
# note: we use the `mutate` function and the pipe character `%>%`, which haven't been introduced yet

flights %>% mutate(travel_time = ifelse((arr_time - dep_time < 0),
2400+(arr_time - dep_time),
arr_time - dep_time)) %>%
arrange(travel_time) %>% select(arr_time, dep_time, travel_time)

# for demonstration purposes, the naive solution is
arrange(flights, (arr_time - dep_time))
# use the variable air_time, which gives amount of time spent in the air, in minutes.
arrange(flights, air_time)

```

Expand Down