library(nycflights13)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#Question 1
lga_to_xna <- flights %>%
  filter(origin == "LGA", dest == "XNA") %>%
  select(tailnum)

lga_to_xna
## # A tibble: 745 × 1
##    tailnum
##    <chr>  
##  1 N722MQ 
##  2 N719MQ 
##  3 N739MQ 
##  4 N719MQ 
##  5 N711MQ 
##  6 N723MQ 
##  7 N711MQ 
##  8 N730MQ 
##  9 N722MQ 
## 10 N719MQ 
## # ℹ 735 more rows
#Question 2
flights_with_airlines <- flights %>%
  left_join(airlines, by = "carrier") %>%
  select(flight, carrier, name)

flights_with_airlines
## # A tibble: 336,776 × 3
##    flight carrier name                    
##     <int> <chr>   <chr>                   
##  1   1545 UA      United Air Lines Inc.   
##  2   1714 UA      United Air Lines Inc.   
##  3   1141 AA      American Airlines Inc.  
##  4    725 B6      JetBlue Airways         
##  5    461 DL      Delta Air Lines Inc.    
##  6   1696 UA      United Air Lines Inc.   
##  7    507 B6      JetBlue Airways         
##  8   5708 EV      ExpressJet Airlines Inc.
##  9     79 B6      JetBlue Airways         
## 10    301 AA      American Airlines Inc.  
## # ℹ 336,766 more rows
#Question 3
no_flight_airports <- airports %>%
  anti_join(flights, by = c("faa" = "origin")) %>%
  anti_join(flights, by = c("faa" = "dest")) %>%
  select(name) %>%
  distinct()

no_flight_airports
## # A tibble: 1,337 × 1
##    name                          
##    <chr>                         
##  1 Lansdowne Airport             
##  2 Moton Field Municipal Airport 
##  3 Schaumburg Regional           
##  4 Randall Airport               
##  5 Jekyll Island Airport         
##  6 Elizabethton Municipal Airport
##  7 Williams County Airport       
##  8 Finger Lakes Regional Airport 
##  9 Shoestring Aviation Airfield  
## 10 Jefferson County Intl         
## # ℹ 1,327 more rows
#Extra Credit
windy_airports <- weather %>%
  filter(wind_speed > 30) %>%  # Filter for high wind speeds
  inner_join(airports, by = c("origin" = "faa")) %>%  # Correct column matching
  select(name) %>%  # Keep only the airport name
  distinct()  # Remove duplicates

windy_airports
## # A tibble: 3 × 1
##   name               
##   <chr>              
## 1 Newark Liberty Intl
## 2 John F Kennedy Intl
## 3 La Guardia