I am trying to use grep
to test whether a vector of strings are present in an another vector or not, and to output the values that are present (the matching pat
To add to Brian Diggs answer.
another way using grepl will return a data frame containing all your values.
toMatch <- myfile$Letter
matches <- myfile[grepl(paste(toMatch, collapse="|"), myfile$Letter), ]
matches
Letter Firstname
1 A1 Alex
2 A6 Alex
4 A1 Bob
5 A9 Chris
6 A6 Chris
Maybe a bit cleaner... maybe?