Select column 2 to last column in R

user2015601 picture user2015601 · Mar 10, 2013 · Viewed 44.3k times · Source

I have a data frame with multiple columns. Now, I want to get rid of the row.names column (column 1), and thus I try to select all the other columns.

E.g.,

newdata <- olddata[,2:10]

is there a default symbol for the last column so I don't have to count all the columns? I tried

newdata <- olddata[,2:]

but it didn't work.

Answer

Se&#241;or O picture Señor O · Mar 10, 2013

I think it's better to focus on wanting to get rid of one column of data and not wanting to select every other column. You can do this as @Arun suggested:

olddata[,-1]

Or:

olddata$ColNameToDelete <- NULL