How to use grepl in every row?

Viewed 2811

I'm trying to search for a pattern in a text using grepl. The problem is that my pattern is a list of names and my text is also a list of texts of the same length. I would like to build a loop that goes over each row and search for a given name in the corresponding text.

edit for clarity

So for example, in this data:

pat <- c("mary", "john", "anthony") 
text <- c("This is a long text about anthony", "This is another long text about john", "This is a final text about mary"). 

I would like search "mary" in the first text, and then "john" in the second, and finally "anthony" in the third one.

3 Answers
Related