An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090413/8ba6ab86/attachment-0001.pl>
toupper does not work in sub + regex
2 messages · Tan, Richard, Gabor Grothendieck
sub only handles replacement strings, not replacement functions.
Your code is the same as:
sub("q_([a-z])[a-zA-Z]*", '\\1', "q_sviRaw")
since toupper('\\1') has no alphabetics so its just literally '\\1' and
the latter is what sub uses.
The gsubfn function in the gsubfn package can deal with replacement
functions:
library(gsubfn)
gsubfn("q_([a-z])[a-zA-Z]*", toupper, "q_sviRaw")
[1] "S" See the home page: http;//gsubfn.googlecode.com, vignette and help page.
On Mon, Apr 13, 2009 at 11:54 AM, Tan, Richard <RTan at panagora.com> wrote:
Hi, I don't know what I am doing wrong to the toupper does not seem
working in sub + regex. ?The following returns 's' not the upper class
'S' as I expect:
sub("q_([a-z])[a-zA-Z]*",toupper('\\1'),"q_sviRaw")
Can someone tell me where I did wrong?
Thanks,
Richard
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.