- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to delete columns by their name in data.table in R?
We can do this by setting the column to NULL
> library(data.table) > df <- data.frame(numbers = 1:10, x = runif(10,25,75)) > data_table <- data.table(df)
To delete one column x
> data_table[, x:=NULL] > data_table numbers 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 10: 10
To delete two columns
> df <- data.frame(numbers = 0:9, x = runif(10,25,75), y=rnorm(10)) > Data_table <- data.table(df) Data_table[, c("x","y"):=NULL] > Data_table numbers 1: 0 2: 1 3: 2 4: 3 5: 4 6: 5 7: 6 8: 7 9: 8 10: 9
- How to drop data frame columns in R by using column name?
- How to remove list elements by their name in R?
- How to add name to data frame columns in R?
- How to select data frame columns based on their class in R?
- How to remove multiple columns from matrix in R by using their names?
- How to extract website name from their links in R?
- How to expand a data frame rows by their index position in R?
- How to subset row values based on columns name in R data frame?
- How to display MySQL Table Name with columns?
- How to extract only factor columns name from an R data frame?
- How to sort a data frame in R by multiple columns together?
- How to divide data frame rows by number of columns in R?
- How to create table of two factor columns in an R data frame?
- How to find the row median of columns having same name in R data frame?
- How to find the row variance of columns having same name in R data frame?