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.

0

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

2 Comments

You don't actually need data(iris) - it's loaded lazily for you
Thank you so much. It saves me so much time

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.