Book Image

R Object-oriented Programming

By : Kelly Black
Book Image

R Object-oriented Programming

By: Kelly Black

Overview of this book

Table of Contents (19 chapters)
R Object-oriented Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
4
Calculating Probabilities and Random Numbers
Package Management
Index

Regular expressions


The commands examined in the previous section lack flexibility, but they are straightforward in their implementation. The use of regular expressions, on the other hand, offers a more elegant approach in many circumstances, but they can be more complex. We briefly examine a few commands that allow string manipulations via regular expressions, and we assume that you are familiar with regular expressions. To get more information about regular expressions in R you can use the help(regular expression) command.

In this section, we will focus on the gregexpr and gsub commands. There are a number of other commands that are listed when you enter the help(gregexpr) command. Also, the commands have a number of options, but we will only examine their most basic forms. As a quick note, the pattern submitted to the grep command discussed earlier can also be a regular expression.

The gregexpr command is a general command that returns the number of results with respect to the regular expression...