Sara
Sara

Reputation: 35

how can use filter function to choose specific varibales

" How many airports in NYC ? Which one has the most flights? Use a bar graph to show the number of flights in each airport."

how can show all airport in NYC I tried this code but did not work only show one variable I tried to use flights data with airports data by filter function but did not work these my code

filter(airports,tzone == "America/New_York" ,dst == "A" )
filter(airports, dst == "A" )
library(nycflights13)
library(tidyverse)
?airports
filter(airports, faa == "NYC", tzone == "America/New_York" )
filter(flights, dest == "NYC")
flights <- flights %>%
  mutate(dep_type = ifelse(dep_delay < 5, "on time", "delayed"))
qplot(x = origin, fill = dep_type, data = flights, geom = "bar")

Upvotes: 0

Views: 61

Answers (1)

MKR
MKR

Reputation: 20095

OP has asked many question to be solved. Lets take one by one.

The number of Airport in NYC can be found by filtering with condition tzone containing 'New_York`.

airports %>%
filter(grepl("New_York", tzone)) %>% summarise(Number_of_Airport_NYC = n())

 #Number_of_Airport_NYC
 #                  <int>
 #1                   519

Maximum number of flights can be found as:

flights %>% group_by(dest) %>%
  summarise(FlightCount = n()) %>%
  filter(FlightCount == max(FlightCount))

#  dest  FlightCount
#  <chr>       <int>
#1 ORD         17283

Number of flights at each airport can be found as:

flights %>% group_by(dest) %>%
      summarise(FlightCount = n())

 #  dest  FlightCount
 #  <chr>       <int>
 #1 ABQ           254
 #2 ACK           265
 #3 ALB           439
  # ... with 102 more rows

Upvotes: 1

Related Questions