[R] Selecting columns whose names contain "mutated" except when they also contain "non" or "un"
peter dalgaard
pdalgd at gmail.com
Wed Apr 25 17:16:57 CEST 2012
On Apr 24, 2012, at 19:15 , Rui Barradas wrote:
>
> Has anyone realized that both 'non' and 'un' end with the same letter? The
> only one we really need to check?
>
> (tmp <- c('mutation','nonmutated','unmutated','verymutated','other'))
>
> i1 <- grepl("muta", tmp)
> i2 <- grepl("nmuta", tmp)
>
> tmp[i1 & !i2]
>
Yes, I was wondering why people were avoiding the obvious use of grepl(). I'm not too happy about the "nmuta" technique though: What about "deletionmutation" and such? Might as well do the safe(r) thing:
i2 <- grepl("unmuta", tmp) | grepl("nonmuta", tmp)
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list