Flummoxed by gsub().
On 23/08/17 18:33, Stefan Evert wrote:
On 23 Aug 2017, at 07:45, Rolf Turner <r.turner at auckland.ac.nz> wrote:
My reading of ?regex led me to believe that
gsub("[:alpha:]","",x)
should give the result that I want.
That's looking for any of the characters a, l, p, h, : .
OK. I see that now. I don't think that it's really stated anywhere that to search for (and possibly change) any one of a string of characters you enclose that string of characters in brackets [ ]. The first example from ?grep makes this "clear" (for some value of the word "clear") once you understand what this example is on about. So it's "obvious" once you've been shown, and totally opaque until then.
What you meant to say was
gsub("[[:alpha:]]","",x)
i.e. the character class [:alpha:] within a character set.
Yup. Got it. Thanks very much. cheers, Rolf
Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276