Deselecting specific columns
You can also drop or deselect columns by prepending the character vector of column names with the -
or !
operators. For e.g., dt[, -c("col1", "col2")]
or dt[, !c("col1", "col2")]
would both return all columns except col1
and col2
.
This is a part of the course
“Data Manipulation with data.table in R”
Exercise instructions
Deselect the columns start_terminal
and end_terminal
from batrips
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Deselect start_terminal and end_terminal columns
drop_terminal_cols <- ___
drop_terminal_cols
This exercise is part of the course
Data Manipulation with data.table in R
Master core concepts about data manipulation such as filtering, selecting and calculating groupwise statistics using data.table.
Just as the <i>i</i> argument lets you filter rows, the <i>j</i> argument of data.table lets you select columns and also perform computations. The syntax is far more convenient and flexible when compared to data.frames.
Exercise 1: Selecting columns from a data.tableExercise 2: Selecting a single columnExercise 3: Selecting columns by nameExercise 4: Deselecting specific columnsExercise 5: Computing on columns the data.table wayExercise 6: Computing in j (I)Exercise 7: Computing in j (II)Exercise 8: Advanced computations in jExercise 9: Computing in j (III)Exercise 10: Combining i and jWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.