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

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Feb 2 18:04:32 CET 2010


Hi,

On Tue, Feb 2, 2010 at 11:47 AM, anna <lippelanna24 at 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 <- datas[,-which(names(datas)=="A")]

(note that indexing with a "negative" vector removes those
rows/columns from your object (instead of picking them)).

-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



More information about the R-help mailing list