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


The grepl() function allows you to search strings using more sophisticated criteria. For example, with grepl() we can get all cities with names that start with the letter "A". To do that, we have to define the pattern we're looking for in such a way that R will understand it. So we use something called regular expressions. In this case, we're looking for all city names that start with "A", so we write:

cities[grepl("^A", cities)]

The "^A" tells R "look in the following vector for everything that starts with the letter A". In this way, we're telling R to match a certain pattern.


From the countries vector, extract all countries with names starting with United. Use the grepl() function.