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

David Winsemius dwinsemius at comcast.net
Tue Feb 2 19:55:09 CET 2010


On Feb 2, 2010, at 12:04 PM, Steve Lianoglou wrote:

> 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)).

But only with numeric vectors.

>
> -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
>
> ______________________________________________
> R-help at r-project.org 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list