How can we check whether a group of characters or a string is present in a vector of strings in R?

r
hackathon
data_wrangling

#1

Hello,

I want to check whether a particular string is present in a vector of strings in R. How can I do this?

Thanks


#2

You can use
match : https://stat.ethz.ch/R-manual/R-devel/library/base/html/match.html

While other methods can also be used in combination with apply methods. I find the above to be the most convenient.


#3

example:
grep(“pattern”, vector of data)

patter is regular expression example “^Vidhya” will match any strings in your vector starting with Vidhya

Check for regular expressions ( be careful for R and Python the special characters are different)