I have this dataframe (DF1)
structure(list(ID = 1:3, Text = c("there was not clostridium", "clostridium difficile positive", "test was OK")), class = "data.frame", row.names = c(NA, -3L))
ID TEXT
1 "there was not clostridium"
2 "clostridium difficile positive"
3 "test was OK"
and dataframe (DF2)
structure(list(ID = 1:3, Microorganisms = c("ESCHERICHIA COLI", "CLOSTRIDIUM DIFFICILE", "FUNGI")), class = "data.frame", row.names = c(NA, -3L))
ID Microorganisms
1 ESCHERICHIA COLI
2 CLOSTRIDIUM DIFFICILE
3 FUNGI
And I would like with regex find matches DF1 and DF2 and put them to a new column like this
ID TEXT Microorganism
1 "there was not clostridium" CLOSTRIDIUM DIFFICILE
2 "clostridium difficile positive" CLOSTRIDIUM DIFFICILE
3 "test was OK" no
I have tried something like this
DF1 %>% mutate(Mikroorganism = ifelse(grepl(DF2$Microorganisms, TEXT), str_extract(TEXT, DF2$Microorganisms), "no"))
But it was not the way.
"difficile". Are you looking for a match of any of the words inDF2, not the string as a whole?