R

Asked • 09/05/19

Drop data frame columns by name?

I have a number of columns that I would like to remove from a data frame. I know that we can delete them individually using something like: df$x <- NULLBut I was hoping to do this with fewer commands.Also, I know that I could drop columns using integer indexing like this: df <- 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 there might be a better way than dropping each column one by one.

1 Expert Answer

By:

Rex C. answered • 09/06/19

Tutor
5 (35)

Experienced Statistics Instructor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.