I often need to remove column lists from data.frame.
I usually do this:
to.remove <- c("hp","drat","wt","qsec") mtcars[,-which(names(mtcars) %in% to.remove)]
which works great.
But I would like to make it cleaner using subset . But it looks like it's a data.frame binding, and then access to the column names as variables, not rows.
For example, this is what I would like to do:
subset(mtcars,select=-to.remove)
Is there a way to force subset use row vectors in a select statement? Or is there another better alternative?
r dataframe
Jesse Mar 23 '12 at 20:12 2012-03-23 20:12
source share