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> <int> <dbl> <chr> <chr>
## 1 ABQ Albuquerque Internati… 35.0 -107. 5355 -7 A America/Den…
## 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… 61.2 -150. 152 -9 A America/Anc…
## 5 ATL Hartsfield Jackson At… 33.6 -84.4 1026 -5 A America/New…
## 6 AUS Austin Bergstrom Intl 30.2 -97.7 542 -6 A America/Chi…
## 7 AVL Asheville Regional Ai… 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/Chi…
## # … with 91 more rows
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> <int> <dbl> <chr> <chr>
## 1 04G Lansdowne Airport 41.1 -80.6 1044 -5 A America/New_…
## 2 06A Moton Field Municipa… 32.5 -85.7 264 -6 A America/Chic…
## 3 06C Schaumburg Regional 42.0 -88.1 801 -6 A America/Chic…
## 4 06N Randall Airport 41.4 -74.4 523 -5 A America/New_…
## 5 09J Jekyll Island Airport 31.1 -81.4 11 -5 A America/New_…
## 6 0A9 Elizabethton Municip… 36.4 -82.2 1593 -5 A America/New_…
## 7 0G6 Williams County Airp… 41.5 -84.5 730 -5 A America/New_…
## 8 0G7 Finger Lakes Regiona… 42.9 -76.8 492 -5 A America/New_…
## 9 0P2 Shoestring Aviation … 39.8 -76.6 1000 -5 U America/New_…
## 10 0S9 Jefferson County Intl 48.1 -123. 108 -8 A America/Los_…
## # … with 1,347 more rows
Find more exercises in Section 13.5.1 of r4ds.
Copyright © 2019 Kirill Müller. Licensed under CC BY-NC 4.0.