In this exercise you will use various data wrangling tools to answer
questions from the data held in separate tables. We’ll use the data in
the nycflights13
package which has relationships between
the tables as follows.
What is the full name (not the three letter code) of the destination airport farthest from any of the NYC airports in the
flights
table?
Save the name as a character value farthest_airport
.
You will need to load the necessary packages
library(tidyverse)
library(nycflights13)
Download starter R script (if desired)
There are several ways to do this using at least two different joins.
I found two solutions that use 5 or 6 functions separated by pipes
(%>%
). Can you do it in fewer?
The details below describe one possible approach.
nycflights13
package by
searching in the “Help” panel in RStudio.name
, distance
, and dest
). You
can use head()
, glimpse()
,
View()
, str()
.arrange()
and
slice()
)by
parameter in the join. e.g. check out
?left_join()
select()
only the destName
columnas.character()
. This converts the data.frame object into a
single value.farthest_airport
Soon we will introduce working with spatial data and doing similar kinds of operations. If you have time to play, see if you can figure out what this does:
airports %>%
distinct(lon,lat) %>%
ggplot(aes(lon, lat)) +
borders("world") +
geom_point(col="red") +
coord_quickmap()
Can you figure out how to map mean delays by destination airport as shown below?
## `summarise()` has grouped output by 'name', 'lat'. You can override using the
## `.groups` argument.
Adapted from R for Data Science