For example, with the data set mtcars
mtcars[ , \"cyl\"]
and
mtcars[ , 2]
both give me the
I often use subset. An example using mtcars
> names(mtcars)
[1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
> cars <- subset(mtcars, select=-c(mpg,cyl))
> names(cars)
[1] "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
There are some other ideas in the answers to this question.
Update: Subset also works for temporary removal of one or more columns by name, just replace mtcars[,-2] with subset(mtcars, select=-cyl).