Let’s say I have a vector string:
words <- c("Guardian","ia","librarian")
If I grep for “ia”, it would return all three.
grep("ia",words) # 1 2 3
How can I make it so that it ONLY finds the 2nd term, the one with nothing else in it?
Note: I can do the opposite, with something like grep(".+ia|ia+.",words) but I’m not sure how to only return the 2nd position in this case.
Use regular expressions to limit grep to just the letters you want: