PDF 100 / 520 #> Source: local data frame [3,306 x 7] #> Groups: year, month, day [365] #> #> year month day d
English · PDF 100
Original PDF page 100
中文 · PDF 100

#> 来源:本地数据框 [3,306 x 7] #> 分组:year, month, day [365] #> #> year month day dep_delay arr_delay distance #> #> 1 2013 1 1 853 851 184 #> 2 2013 1 1 290 338 1134 #> 3 2013 1 1 260 263 266 #> 4 2013 1 1 157 174 213 #> 5 2013 1 1 216 222 708 #> 6 2013 1 1 255 250 589 #> # ... 还有 3,300 多行,以及 1 个更多变量: #> # air_time

  • 找出所有大于某个阈值的分组:

popular_dests <- flights %>% group_by(dest) %>% filter(n() > 365) popular_dests #> 来源:本地数据框 [332,577 x 19] #> 分组:dest [77] #> #> year month day dep_time sched_dep_time dep_delay #> #> 1 2013 1 1 517 515 2 #> 2 2013 1 1 533 529 4 #> 3 2013 1 1 542 540 2 #> 4 2013 1 1 544 545 -1 #> 5 2013 1 1 554 600 -6 #> 6 2013 1 1 554 558 -4 #> # ... 还有 3.326e+05 多行,以及 13 个更多变量: #> # arr_time , sched_arr_time , #> # arr_delay , carrier , flight , #> # tailnum , origin , dest , #> # 航空时间 , distance , hour , #> # minute , time_hour

  • 标准化以计算每个组的指标:

popular_dests %>% filter(arr_delay > 0) %>% mutate(prop_delay = arr_delay / sum(arr_delay)) %>% select(year:day, dest, arr_delay, prop_delay) #> 来源:本地数据框 [131,106 x 6] #> 分组:dest [77] #> #> year month day dest arr_delay prop_delay #> #> 1 2013 1 1 IAH 11 1.11e-04