DATA MINING
Desktop Survival Guide by Graham Williams |
|||||
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.