[R] remove columns having a partial match name

jim holtman jholtman at gmail.com
Wed Jul 18 14:04:40 CEST 2007


DATA_OK <- DATA[-grep("^Start", names(DATA)),]

On 7/18/07, João Fadista <Joao.Fadista at agrsci.dk> wrote:
> Dear all,
>
> I would like to know how can I retrieve a data.frame without the columns that have a partial match name. Let´s say that I have a data.frame with 200 columns and 100 of them have the name "StartX", with X being the unique part for each column name. I want to delete all columns that have the name starting with "Start". I´ve tried to do this but it doesn´t work:
>
> > DATA_OK <- DATA[,-match(("Start*"),names(DATA))]
> > dim(DATA_OK)
> NULL
>
>
> Thanks in advance.
> Best regards
>
> João Fadista
> Ph.d. student
>
>
>
>         UNIVERSITY OF AARHUS
> Faculty of Agricultural Sciences
> Dept. of Genetics and Biotechnology
> Blichers Allé 20, P.O. BOX 50
> DK-8830 Tjele
>
> Phone:   +45 8999 1900
> Direct:  +45 8999 1900
> E-mail:  Joao.Fadista at agrsci.dk <mailto:Joao.Fadista at agrsci.dk>
> Web:     www.agrsci.org <http://www.agrsci.org/>
> ________________________________
>
> News and news media <http://www.agrsci.org/navigation/nyheder_og_presse> .
>
> This email may contain information that is confidential. Any use or publication of this email without written permission from Faculty of Agricultural Sciences is not allowed. If you are not the intended recipient, please notify Faculty of Agricultural Sciences immediately and delete this email.
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list