Let's say I have a vector as follows:
patient_condition <- c("Pre_P1","Post_P1","Enriched_Post_P1","Post_P1_2","Pre_P2","Post_P2", "P3_Pre")
to_match <- c("P1","P2","P3")
I want to create another vector such that the new vector only contains value in to_match if it is a substring.
[1] "P1" "P1" "P1" "P1" "P2" "P2" "P3"
Any help is appreciated. Thank you!