結合 i、j 與 by(I)
在這個練習中,你會同時使用 i、j 與 by 參數,找出每個起始站的「第一趟與最後一趟」騎乘。回想一下,data.table 會先在 i 中篩選列,接著用 by 分組,最後在 j 中計算運算式。
本練習屬於課程
R 的 data.table 資料操作
練習說明
- 依
start_date欄位將batrips由小到大排序。 - 依
start_station分組各列。 - 取出
start_date的第一列與最後一列。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Find the first and last ride for each start_station
first_last <- batrips[___,
.(start_date = ___),
by = ___]
first_last