Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Extract elements from list with non-exact match in R [duplicate]

$
0
0

This question already has an answer here:

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


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>