Using .SD (I)
.SD together with .SDcols is an incredibly powerful feature that makes computing on multiple columns so much easier.
.SDis a special symbol which stands for Subset of Data.SDcolsholds the columns that should be included in.SD
Questo esercizio fa parte del corso
Data Manipulation with data.table in R
Istruzioni dell'esercizio
- For each month, find the row corresponding to the shortest trip (by using
which.min()onduration). - The result should contain the
month,start_station,end_station,start_date,end_date, anddurationcolumns.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
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