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-2006 Graham.Williams@togaware.com
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.