Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Strings basics
Regular expressions
Modifying strings


So we know how to check if a certain pattern or character exists in a vector. How can we select it?

Suppose we want to make a subset of all the countries with an "a" in their name. We will use the values returned by the grepl() function. Remember, this function returns TRUE or FALSE for each element in the vector; the subset function will return only those fields that are TRUE. To get a subset, we use square brackets []:

countries[grepl("a", countries)]


From the countries vector, subset all country names containing an "r".