从hflights降序排列的总数[关闭]

问题描述 投票:-3回答:2

我有hflights数据集,我需要计算方面的帮助。我在搜索,但是没有找到可以帮助我的东西对于一年中的每一天,计算飞行总数并安排其下降时间

install.packages("hflights")
library(hflights)
data(hflights)
tail(hflights,n=15)
class(hflights)
summary(hflights)

航班表

enter image description here

r
2个回答
0
投票

您可以将count中的dplyrsort = TRUE一起使用

library(dplyr)
hflights %>% count(Year, Month, DayofMonth, sort = TRUE)

# A tibble: 365 x 4
#    Year Month DayofMonth     n
#   <int> <int>      <int> <int>
# 1  2011     8          4   706
# 2  2011     8         11   706
# 3  2011     8         12   706
# 4  2011     8          5   705
# 5  2011     8          3   704
# 6  2011     8         10   704
# 7  2011     1          3   702
# 8  2011     7          7   702
# 9  2011     7         14   702
#10  2011     7         28   701
# … with 355 more rows

或带有group_bysummarise

hflights %>% 
    group_by(Year, Month, DayofMonth) %>% 
    summarise(n = n()) %>% 
    arrange(desc(n))

0
投票

可能是这样,但是如果没有更多信息,这是我所能做的最好的。这显示了每天来自数据集的航班总数。我使用了库tidyverse

hflights %>%
  group_by(Year, DayofMonth,DayOfWeek) %>% 
  count()
© www.soinside.com 2019 - 2024. All rights reserved.