Arrange within a group with dplyr

后端 未结 2 802
无人共我
无人共我 2021-01-17 16:44

I am using the library(nycflights13) and I use the following command to group_by month and day, select the top 3 rows within each group and then sort in descending order wit

2条回答
  •  余生分开走
    2021-01-17 17:19

    You need to add .by_group=T to arrange within groups.

    flights %>%
       group_by(month, day) %>%
       top_n(3, dep_delay) %>%
       arrange(dep_delay, .by_group = TRUE)
    
    

提交回复
热议问题