[R] Selecting columns whose names contain "mutated" except when they also contain "non" or "un"

Bert Gunter gunter.berton at gene.com
Mon Apr 23 19:01:13 CEST 2012


Below.

-- Bert

On Mon, Apr 23, 2012 at 9:10 AM, Paul Miller <pjmiller_57 at yahoo.com> wrote:
> Hello All,
>
> Started out awhile ago trying to select columns in a dataframe whose names contain some variation of the word "mutant" using code like:
>
> names(KRASyn)[grep("muta", names(KRASyn))]
>
> The idea then would be to add together the various columns using code like:
>
> KRASyn$Mutant_comb <- rowSums(KRASyn[grep("muta", names(KRASyn))])
>
> What I discovered though, is that this selects columns like "nonmutated" and "unmutated" as well as columns like "mutated", "mutation", and "mutational".
>
> So I'd like to know how to select columns that have some variation of the word "mutant" without the "non" or the "un". I've been looking around for an example of how to do that but haven't found anything yet.

You can't, because you have not provided a full specification of what
can be selected and what can't. Software can only do what you tell it
to -- it cannot read minds. Once you have provided a a complete and
accurate specification of inclusion/exclusion criteria, it should be
easy to write a regex procedure.

"The fault, dear Brutus, lies not in the stars but in ourselves."

-- Bert





>
> Can anyone show me how to select the columns I need?
>
> Thanks,
>
> Paul
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list