> -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Steve Lianoglou > Sent: Tuesday, February 02, 2010 9:05 AM > To: anna > Cc: [email protected] > Subject: Re: [R] Deleting many columns of a data frame with > the same name ina row > > Hi, > > On Tue, Feb 2, 2010 at 11:47 AM, anna > <[email protected]> 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(na mes(datas)=="A")))) > > but it worked > > For what it's worth, you could also have done: > > clean <- datas[,-which(names(datas)=="A")] > > (note that indexing with a "negative" vector removes those > rows/columns from your object (instead of picking them)).
I would recommend replacing datas[, -which(names(data)=="A")] with datas[, names(data)!="A"] because the former returns a zero-column data.frame if there are columns of datas named "A". (which(rep(F,n))->integer(0) and -integer(0) is identical to integer(0), which selects no elements). The latter returns the entire data.frame in the case. Logical subscripts are your friend. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > > -steve > > -- > Steve Lianoglou > Graduate Student: Computational Systems Biology > | Memorial Sloan-Kettering Cancer Center > | Weill Medical College of Cornell University > Contact Info: http://cbio.mskcc.org/~lianos/contact > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

