0

I know that one should be able to delete columns with -c() and the column names. But weirdly it doesn't work in my R. What am I doing wrong?

library(data.table)
df <- data.frame(x1=c(1,2,3), x2=c(4,5,6), x3=c(7,8,9))
df <- df[,-c("x1", "x2")]

I tried this and expected it to remove columns x1 and x2 but instead I get this error:

Error in -c("x1", "x2") : invalid argument to unary operator

zx8754
  • 52,746
  • 12
  • 114
  • 209

0 Answers0