2021年1月23日星期六

What is this arrange function in the second line doing here?

I'm currently reviewing R for Data Science when I encounter this chunk of code. I don't understand the necessity of the arrange function here. Doesn't arrange function just reorder the rows?

library(tidyverse)  library(nycflights13))  flights %>%  arrange(tailnum, year, month, day) %>%  group_by(tailnum) %>%  mutate(delay_gt1hr = dep_delay > 60) %>%  mutate(before_delay = cumsum(delay_gt1hr)) %>%  filter(before_delay < 1) %>%  count(sort = TRUE)  

However, it does output differently with or without the arrange function, as shown below:

#with the arrange function  tailnum     n     <chr>   <int>   1 N954UW    206   2 N952UW    163   3 N957UW    142   4 N5FAAA    117   5 N38727     99   6 N3742C     98   7 N5EWAA     98   8 N705TW     97   9 N765US     97  10 N635JB     94  # ... with 3,745 more rows  

and

#Without the arrange function  tailnum     n     <chr>   <int>   1 N952UW    215   2 N315NB    161   3 N705TW    160   4 N961UW    139   5 N713TW    128   6 N765US    122   7 N721TW    120   8 N5FAAA    117   9 N945UW    104  10 N19130    101  # ... with 3,774 more rows  

I'd appreciate it if you can help me understand this.

https://stackoverflow.com/questions/65866938/what-is-this-arrange-function-in-the-second-line-doing-here January 24, 2021 at 11:41AM

没有评论:

发表评论