Projects : Nycflights23

Data ที่นำมาเล่นวันนี้จะเป็นตัว Nycflights23 เป็นข้อมูลการบินของ New Yorks City Airport ในปี 2023 และข้อมูลสภาพอากาศ, ข้อมูล Airport, ข้อมูลของตัวเครื่องบิน

data("flights")
View(flights)
glimpse(flights)
glimpse(weather)
?flights

# 1.How many flight that  delay between 
# Nov - Dec group by day

flight_counts <- flights %>%
  filter(month %in% c(11, 12) & dep_delay > 0) %>%
  group_by(month, day) %>%
  arrange(-day) %>%
  summarise(count_total = n()) %>%
  View()

# 2.top 5 flight that contain most distance 
# flight start with (1,2,3)

top5flightdis <- flights %>%
  filter(grepl("^[123]", flight)) %>%
  select(flight, distance) %>%
  group_by(flight) %>%
  summarise(total_distance = sum(distance)) %>%
  arrange(-total_distance) %>%
  head(5) %>%
  View()

# 3.How many flight that dest at LAS, LIT
# Departure between 14.00 - 16.00

flightdep <- flights %>%
  select(flight, dest, dep_time) %>%
  filter(dest %in% c("LAS","LIT")
         & dep_time >= 1400 
         & dep_time <= 1600) %>%
  group_by(dest) %>%
  summarise(flight_count =n())

result3 <- flightdep %>%
  inner_join(airports, by = c("dest" = "faa")) %>%
  rename(airport = name) %>%
  select(airport, flight_count) %>%
  View()

# 4.Departed in Summer (July, August, September)

summer_carrier <- flights %>%
  select(carrier,month) %>%
  filter(month %in% c(7,8,9)) %>%
  group_by(carrier,month) %>%
  summarise(total = n()) 

result4 <- summer_carrier %>%
  inner_join(airlines, by = "carrier") %>%
  select(carrier, name, month, total) %>%
  View()

# 5 Arrived more than 2 hours late but didn't leave late
# display On-Time or Early 

result5 <- flights %>%
  select(flight, arr_delay, dep_delay) %>%
  filter(arr_delay > 120, dep_delay <= 0) %>%
  mutate(status = if_else(dep_delay == 0,
                          "On-Time",
                          "Early")) %>%
                          View()
Posted in ,

ใส่ความเห็น