There are two problems in the OP's code. One is that the column names that we need to delete is not quoted. Second, the select
argument doesn't take -
argument. So we can use setdiff
to get the column names that are not "ItemId_na" or "Item.Type1_na".
subset(test_input,select = setdiff(names(test_input),
c("ItemId_na", "Item.Type1_na")))
The select
option from dplyr
takes the -
option
library(dplyr)
test_input %>%
select(-ItemId_na, -Item.Type1_na)
data
test_input <- structure(list(ID = c(1L, 1L, 1L, 1L, 2L,
2L), Category = c("X",
"X", "X", "X", "X", "X"), ItemId_na = c(2L, 2L, 2L, 2L,
3L, 3L
), Item.Type1_na = c(1L, 2L, 3L, 4L, 1L, 2L)),
.Names = c("ID",
"Category", "ItemId_na", "Item.Type1_na"),
row.names = c(NA, 6L), class = "data.frame")