Skip to content
Prev 388107 / 398502 Next

R grep question

Hi Kai,
You may find %in% easier than grep when multiple matches are needed:

match_strings<-c("MLH1","MSH2")
CRC<-data.frame(gene.all=c("MLH1","MSL1","MSH2","MCC3"))
CRC$MMR.gene<-ifelse(CRC$gene.all %in% match_strings,"Yes","No")

Composing your match strings before applying %in% may be more flexible
if you have more than one selection to make.

On Fri, May 28, 2021 at 1:57 AM Marc Schwartz via R-help
<r-help at r-project.org> wrote: