2

Possible Duplicate:
Drop Columns R Data frame

I have a list of variables I would like to drop from IRIS table as follow:

dropList <- c("Sepal.Length", "Sepal.Width")

How I can use this list to drop from IRIS data frame? (I don't want to refer to positions explicitly)

Thanks.

Community
  • 1
  • 1
AdamNYC
  • 18,859
  • 28
  • 93
  • 150

1 Answers1

8

There's some other ways you can do this, like using the select argument of subset, but if dropList is coming to you as a character vector from somewhere else, this works pretty well.

data(iris)
dropList <- c("Sepal.Length", "Sepal.Width")
iris2 <- iris[, !colnames(iris) %in% dropList]
Marius
  • 54,802
  • 15
  • 100
  • 97