[R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna
Hi, I have a data frame datas with half of the columns with the same name A. I want to delete all those columns from the data frame so here is what I did: datas$A - NULL The problem is that it deleted only one column, I would have to do it as many times as there are A columns. Is there a way to

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna
This is what I just found now but I guess there is a simpler way: datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A but it worked - Anna Lippel -- View this message in context:

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Gabor Grothendieck
Try: newdf - datas[names(datas) != A] On Tue, Feb 2, 2010 at 11:47 AM, anna lippelann...@hotmail.com wrote: This is what I just found now but I guess there is a simpler way: datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A but it worked - Anna Lippel --

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Phil Spector
Anna - You could also look at the problem from the other direction: data[,names(datas) != 'A'] - Phil Spector Statistical Computing Facility Department of Statistics

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Jeff Laake
Here is one way with an example: datas=data.frame(x=1:3,A=1:3,A=1:3) names(datas)=c(x,A,A) datas datas=datas[,names(datas)!=A,drop=FALSE] datas On 2/2/2010 8:35 AM, anna wrote: Hi, I have a data frame datas with half of the columns with the same name A. I want to delete all those columns from

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Uwe Ligges
datas[ , A != colnames(datas)] Uwe Ligges On 02.02.2010 17:35, anna wrote: Hi, I have a data frame datas with half of the columns with the same name A. I want to delete all those columns from the data frame so here is what I did: datas$A- NULL The problem is that it deleted only one column, I

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Steve Lianoglou
Hi, On Tue, Feb 2, 2010 at 11:47 AM, anna lippelann...@hotmail.com wrote: This is what I just found now but I guess there is a simpler way: datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A but it worked For what it's worth, you could also have done: clean -

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Henrique Dallazuanna
Try this: subset(DF, select = setdiff(names(DF), A)) On Tue, Feb 2, 2010 at 2:47 PM, anna lippelann...@hotmail.com wrote: This is what I just found now but I guess there is a simpler way: datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A but it worked -

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna
thanks this is actually shorter :) - Anna Lippel -- View this message in context: http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460208.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna
yes it looks really simpler, thank you! - Anna Lippel -- View this message in context: http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460213.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread David Winsemius
On Feb 2, 2010, at 12:04 PM, Steve Lianoglou wrote: Hi, On Tue, Feb 2, 2010 at 11:47 AM, anna lippelann...@hotmail.com wrote: This is what I just found now but I guess there is a simpler way: datas[which(names(datas)==A)]- list(rep(NULL,length(which(names(datas)==A but it worked