IniziaInizia gratis

Selecting columns by name

DT[, c("col1", "col2")] returns a data.table with two columns, just like a data.frame.

Alternatively, you can also select columns by passing a list with each element referring to the column name as if it were a variable, i.e., DT[, .(col1, col2)]. Note the absence of quotes, i.e., "" around column names here.

Questo esercizio fa parte del corso

Data Manipulation with data.table in R

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Select bike_id and trip_id using a character vector
df_way <- batrips[___]
df_way
Modifica ed esegui il codice