中文 · PDF 78
通过基于变量名的操作,快速缩放到有用的子集。
select() 对于 flight 数据来说用处不大,因为我们只有 19 个变量,但你仍然可以大致了解它的用法:
# 按名称选择列 select(flights, year, month, day) #> # A tibble: 336,776 × 3 #> year month day #> #> 1 2013 1 1 #> 2 2013 1 1 #> 3 2013 1 1 #> 4 2013 1 1 #> 5 2013 1 1 #> 6 2013 1 1 #> # ... with 3.368e+05 more rows # 选择 year 到 day 之间的所有列(含两端) select(flights, year:day) #> # A tibble: 336,776 × 3 #> year month day #> #> 1 2013 1 1 #> 2 2013 1 1 #> 3 2013 1 1 #> 4 2013 1 1 #> 5 2013 1 1 #> 6 2013 1 1 #> # ... with 3.368e+05 more rows # 选择除 year 到 day(含两端)之外的所有列 select(flights, -(year:day)) #> # A tibble: 336,776 × 16 #> dep_time sched_dep_time dep_delay arr_time sched_arr_time #> #> 1 517 515 2 830 819 #> 2 533 529 4 850 830 #> 3 542 540 2 923 850 #> 4 544 545 -1 1004 1022 #> 5 554 600 -6 812 837 #> 6 554 558 -4 740 728 #> # ... with 3.368e+05 more rows, and 12 more variables: #> # arr_delay , carrier , flight , #> # tailnum , origin , dest , air_time , #> # 距离 , 小时 , 分钟 , #> # time_hour
你可以在 select() 中使用许多辅助函数: