[R] remove multiple columns by name from dataframe

Sarah Goslee sarah.goslee at gmail.com
Thu Jul 23 16:15:13 CEST 2009


There are several ways to do it. Here's one:

fakedata <- data.frame(col1 = runif(10), col2 = runif(10), col3 = runif(10))
delete <- c("col1", "col3")
fakedata2 <- fakedata[, !(colnames(fakedata) %in% delete), drop=FALSE]

Sarah

On Thu, Jul 23, 2009 at 9:49 AM, Anne Skoeries<home at anne-skoeries.de> wrote:
> Hi there,
>
> I'm trying to remove multiple columns by name from a data.frame. As a
> result I need to get back the modified data.frame without the removed
> columns. My columns I want to delete are listed in a vector called
> "delete".
>

-- 
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list