Drop Columns R Data frame

Posted by Btibert3 on Stack Overflow See other posts from Stack Overflow or by Btibert3
Published on 2011-01-05T14:34:29Z Indexed on 2011/01/05 21:53 UTC
Read the original article Hit count: 148

Filed under:

I have a number of columns that I would like to drop from a data frame. I know that we can drop them using something like:

df$x <- NULL

but I was hoping to do this with less commands.

Also, I know that I could use this:

df[ -c(1,3:6, 12) ]

but I am concerned that the relative position of my variables may change.

Given how powerful R is, I figured I would ask to see if there is another way beyond dropping each column 1 by 1.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about r