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.
Este exercício faz parte do curso
Data Manipulation with data.table in R
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Select bike_id and trip_id using a character vector
df_way <- batrips[___]
df_way