grep and regular expressions

grep() in R works exactly as it does in every UNIX-based operating system. Closely related to grep() (in fact, R groups them together and treats them as a group of functions), various other functions can be found. In this section, only grepl(), gregexpr(), and gsub() will be examined. One thing that all these functions have in common is that they perform an action based on a string pattern. The description of the functions are as follows:

  • grep(): This returns the indexes of the elements in a vector that match a string pattern. If the value is set to TRUE, it returns the values instead of the indexes.
  • grepl(): This returns a logical vector of the same length as the input vector, denoting whether the sought pattern was ...

Get Learning Shiny now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.