Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Substitution

Remove all decimal points from a string representing a real number using sub with either limiting the replacement to digits, or else substituting any characters:

> sub("\\.[[:digit:]]*$", "", "12345.67")
[1] "12345"
> sub("[.].*", "", "12345.67")
[1] "12345"

In the second example the ``.'' does not need to be escaped since it appears in a character class.



Copyright © 2004-2010 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010