Book Image

Mastering Scientific Computing with R

Book Image

Mastering Scientific Computing with R

Overview of this book

Table of Contents (17 chapters)
Mastering Scientific Computing with R
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

String processing and pattern matching


Pattern matching is concerned with identifying patterns of characters in strings, and has a long history in computer programming outside of its use in R. The simplest kind of pattern matching would be to ask whether a given character is equal to a value or a group of values, which would be a simple program to write in nearly any language, but it would also have very limited functionality. A bigger problem is dealing with patterns of characters; for example, uppercase alphabet characters, numerals, and so on. A language for describing patterns of string characters has been identified and adopted in many languages including R, called regular expressions, which the grep family of R functions is based on. We will first discuss these functions and then delve into using regular expressions.

The grep family of functions includes a number of similar functions for identifying and replacing patterns of text. The most commonly used functions are as follows:

  • grep...