very simple question...but I'm confused

I know that "data[ , c(1)]" means extracting the first column of the dataset.

But what is "data[ , c(-1)]"?

Using a negative number removes the column so using -1 gives you all of the columns except the first one.

1 Like

Thank you!
and plus, if I suppose that the first column is named "variable1",
is "data[ , c(-variable1)] work?
Or what should I do to make same output with the "data[ , c(-1)]", but if I wanna designate with name of the column, not the number of column?

I do not know of an elegant way to eliminate column by name using base R. That may just be my ignorance. I would use the select() function from dplyr to do that.

select(data, -variable1, -variable2)

thanks for your kind answer again :slight_smile:

Not elegant but this works with base R

data[ , !(names(data) %in% c("variable1"))]

I'll use it. thank you

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.