我们可以通过将列设置为NULL来实现
> library(data.table) > df <- data.frame(numbers = 1:10, x = runif(10,25,75)) > data_table <- data.table(df)
删除一列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
删除两列
> 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