Skip to content
Back to formatted view

Raw Message

Message-ID: <3E91D72E.80730700@statistik.uni-dortmund.de>
Date: 2003-04-07T19:53:18Z
From: Uwe Ligges
Subject: subsetting a dataframe

Chris Handorf wrote:
> 
> How does one remove a column from a data frame when the name of
> the column to remove is stored in a variable?
> 
> For Example:
> 
> colname <- "LOT"
> 
> newdf <- subset(olddf,select = - colname)
> 
> The above statement will give an error, but thats what I'm trying to
> accomplish.
> 
> If I had used:
> 
> newdf <- subset(olddf,select = - LOT)
> 
> then it would have worked, but as I said the column name is stored in a
> variable
> so I can't just enter it explicity.

What about
 subset(olddf, select= -get(colname))
or
 olddf[, names(olddf) != colname]

Uwe Ligges