This question already has an answer here:
- Find the words in list of strings 1 answer
I would like to identify whether there are common elements between two different list of compounds.
I successfully used the intersect()
function to extract the majority of the values that have identical names (e.g. "drug1" and "drug1").
However, I noticed that multiple drugs were not identified with this method, as they are written differently in the two lists. For example one compound is written with the alternative name ("Drug1" vs "AlternativeName1 (Drug1)") and this is obviously not recognised by the inteserc()
function.
Is there a way to make the search parameters more loose to be able to extract matching part of the names even if in the presence of parentheses or other parts?
list1 <- c("Drug1", "Drug2", "Drug3")
list2 <- c("AlternativeName (Drug1)", "Drug 4", "Drug3 (OtherNames)")
I would like to obtain:
drug_list <- c("Drug1", "Drug3")
Thanks