Get startedGet started for free

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.

This exercise is part of the course

Data Manipulation with data.table in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Select bike_id and trip_id using a character vector
df_way <- batrips[___]
df_way
Edit and Run Code