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

Six focused tasks


We first examine six specific tasks. These operations are to determine the length of a string, location of a substring, extract or replace a substring, change the case of a string, split a string into separate parts, and express a combination of objects as a single string. Please note that the examples will make extensive use of the definition of the url vector that is defined in the previous section.

Determining the length of a string

The nchar command is used to determine the length of a string. This option can be used as part of a simple statistic for a set of strings or can be part of a programming tool when it is necessary to iterate over a string. You can specify how the count is calculated with options to count the number of characters, bytes, or width of the resulting string. In most cases, these values will be the same but can differ depending on the Unicode settings for your environment:

> nchar(urls)
[1] 52 62 41 42

The nchar command tries to coerce its argument...