Airports accessed

Find the airports that are serviced by at least one flight.

airports %>%
  semi_join(flights, by = c(_____))

airports %>%
  anti_join(flights, by = c(_____))

► Solution:

airports %>%
  semi_join(flights, by = c("faa" = "dest"))
## # A tibble: 101 x 8
##    faa   name                         lat    lon   alt    tz dst   tzone        
##    <chr> <chr>                      <dbl>  <dbl> <dbl> <dbl> <chr> <chr>        
##  1 ABQ   Albuquerque International…  35.0 -107.   5355    -7 A     America/Denv…
##  2 ACK   Nantucket Mem               41.3  -70.1    48    -5 A     America/New_…
##  3 ALB   Albany Intl                 42.7  -73.8   285    -5 A     America/New_…
##  4 ANC   Ted Stevens Anchorage Intl  61.2 -150.    152    -9 A     America/Anch…
##  5 ATL   Hartsfield Jackson Atlant…  33.6  -84.4  1026    -5 A     America/New_…
##  6 AUS   Austin Bergstrom Intl       30.2  -97.7   542    -6 A     America/Chic…
##  7 AVL   Asheville Regional Airport  35.4  -82.5  2165    -5 A     America/New_…
##  8 BDL   Bradley Intl                41.9  -72.7   173    -5 A     America/New_…
##  9 BGR   Bangor Intl                 44.8  -68.8   192    -5 A     America/New_…
## 10 BHM   Birmingham Intl             33.6  -86.8   644    -6 A     America/Chic…
## # … with 91 more rows

Airports not flown to

Which airports did not have direct connections in 2013?

► Solution:

airports %>%
  anti_join(flights, by = c("faa" = "dest"))
## # A tibble: 1,357 x 8
##    faa   name                       lat    lon   alt    tz dst   tzone          
##    <chr> <chr>                    <dbl>  <dbl> <dbl> <dbl> <chr> <chr>          
##  1 04G   Lansdowne Airport         41.1  -80.6  1044    -5 A     America/New_Yo…
##  2 06A   Moton Field Municipal A…  32.5  -85.7   264    -6 A     America/Chicago
##  3 06C   Schaumburg Regional       42.0  -88.1   801    -6 A     America/Chicago
##  4 06N   Randall Airport           41.4  -74.4   523    -5 A     America/New_Yo…
##  5 09J   Jekyll Island Airport     31.1  -81.4    11    -5 A     America/New_Yo…
##  6 0A9   Elizabethton Municipal …  36.4  -82.2  1593    -5 A     America/New_Yo…
##  7 0G6   Williams County Airport   41.5  -84.5   730    -5 A     America/New_Yo…
##  8 0G7   Finger Lakes Regional A…  42.9  -76.8   492    -5 A     America/New_Yo…
##  9 0P2   Shoestring Aviation Air…  39.8  -76.6  1000    -5 U     America/New_Yo…
## 10 0S9   Jefferson County Intl     48.1 -123.    108    -8 A     America/Los_An…
## # … with 1,347 more rows

More exercises

Find more exercises in Section 13.5.1 of r4ds.

Copyright © 2019 Kirill Müller. Licensed under CC BY-NC 4.0.