如何使用过滤功能来选择特定变量

how can use filter function to choose specific varibales

"纽约市有多少个机场?哪个机场的航班最多?使用条形图显示每个机场的航班数量。"

如何显示纽约市的所有机场 我试过这段代码但没有用只显示一个变量 我尝试通过过滤功能将航班数据与机场数据结合使用,但没有成功 这些是我的代码

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")

OP 提出了很多需要解决的问题。让我们一一道来。

可以通过条件 tzone 包含“New_York”的条件进行过滤来找到纽约市的机场数量。

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

 #Number_of_Airport_NYC
 #                  <int>
 #1                   519

可找到的最大航班数为:

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

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

各机场的航班数量为:

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

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