[R] How to exclude a column by name?

2009-05-27 Thread Zeljko Vrba
Given an arbitrary data frame, it is easy to exclude a column given its index: df[,-2]. How to do the same thing given the column name? A naive attempt df[,-name] did not work :) __ R-help@r-project.org mailing list

Re: [R] How to exclude a column by name?

2009-05-27 Thread Linlin Yan
Hope this helps: df - data.frame(matrix(1:10,2)) df X1 X2 X3 X4 X5 1 1 3 5 7 9 2 2 4 6 8 10 df[,-2] X1 X3 X4 X5 1 1 5 7 9 2 2 6 8 10 df[,-which(names(df)==X2)] X1 X3 X4 X5 1 1 5 7 9 2 2 6 8 10 On Wed, May 27, 2009 at 6:37 PM, Zeljko Vrba zv...@ifi.uio.no wrote:

Re: [R] How to exclude a column by name?

2009-05-27 Thread Paul Hiemstra
Zeljko Vrba wrote: Given an arbitrary data frame, it is easy to exclude a column given its index: df[,-2]. How to do the same thing given the column name? A naive attempt df[,-name] did not work :) __ R-help@r-project.org mailing list

Re: [R] How to exclude a column by name?

2009-05-27 Thread Zeljko Vrba
On Wed, May 27, 2009 at 12:52:41PM +0200, Paul Hiemstra wrote: This piece of code does the trick. Most important is the which() command: df = data.frame(a = runif(10), b = runif(10)) df[,-which(names(df) == a)] Thanks to you and Linlin. It did not occur to me to use which(); I thought

Re: [R] How to exclude a column by name?

2009-05-27 Thread Peter Dalgaard
Paul Hiemstra wrote: Zeljko Vrba wrote: Given an arbitrary data frame, it is easy to exclude a column given its index: df[,-2]. How to do the same thing given the column name? A naive attempt df[,-name] did not work :) __ R-help@r-project.org

Re: [R] How to exclude a column by name?

2009-05-27 Thread Henrique Dallazuanna
You can try this: DF[,columnName] - NULL On Wed, May 27, 2009 at 7:37 AM, Zeljko Vrba zv...@ifi.uio.no wrote: Given an arbitrary data frame, it is easy to exclude a column given its index: df[,-2]. How to do the same thing given the column name? A naive attempt df[,-name] did not work :)

Re: [R] How to exclude a column by name?

2009-05-27 Thread Stavros Macrakis
On Wed, May 27, 2009 at 6:37 AM, Zeljko Vrba zv...@ifi.uio.no wrote: Given an arbitrary data frame, it is easy to exclude a column given its index: df[,-2]. How to do the same thing given the column name? A naive attempt df[,-name] did not work :) Various ways: Boolean index vector:

Re: [R] How to exclude a column by name?

2009-05-27 Thread Dieter Menne
Peter Dalgaard P.Dalgaard at biostat.ku.dk writes: Or, BTW, you can use within() aq - within(airquality, rm(Day)) Please add this as an example to the docs of within. Dieter __ R-help@r-project.org mailing list

Re: [R] How to exclude a column by name?

2009-05-27 Thread Wacek Kusnierczyk
Dieter Menne wrote: Peter Dalgaard P.Dalgaard at biostat.ku.dk writes: Or, BTW, you can use within() aq - within(airquality, rm(Day)) Please add this as an example to the docs of within. possibly with the slightly more generic unwanted - 'Day' aq -