始める無料で始める

`.SD` を使う(I)

.SD.SDcols を組み合わせると、複数列に対する計算がぐっと簡単になります。

  • .SDSubset of Data(データのサブセット)を表す特別な記号です。
  • .SDcols.SD に含める列を指定します。

この演習はコースの一部です

R の data.table によるデータ操作

コースを見る

演習の手順

  • 各月について、duration に対して which.min() を使い、最短の行程に対応する行を見つけてください。
  • 結果には monthstart_stationend_stationstart_dateend_dateduration の列を含めます。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

relevant_cols <- c("start_station", "end_station", 
                   "start_date", "end_date", "duration")

# Find the row corresponding to the shortest trip per month
shortest <- batrips[, ___, 
                    by = month(start_date), 
                    .SDcols = ___]
shortest
コードを編集して実行