Dear Alrik
This may seem a silly suggestion but why not just define new functions
PMIN and PMAX to call pmin and pmax. Obviously that does not solve your
problem if it is more general than your example.
On 28/02/2015 13:16, Alrik Thiem wrote:
Dear Gabor,
Many thanks. Works like a charm, but I can't get it to work with
"pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"
i.e., with strings where there're no integers following the components in the
pmin/pmax functions. Could this be generalized to handle both cases?
Best wishes,
Alrik
-----Ursprüngliche Nachricht-----
Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
Gesendet: Samstag, 28. Februar 2015 13:35
An: Alrik Thiem
Cc: r-help@r-project.org
Betreff: Re: [R] Substring replacement in string
On Fri, Feb 27, 2015 at 5:19 PM, Alrik Thiem <alrik.th...@gmail.com> wrote:
I would like to replace all lower-case letters in a string that are not part
of certain fixed expressions. For example, I have the string:
"pmin(pmax(pmin(x1, X2), pmin(X3, X4)) == Y, pmax(Z1, z1))"
Where I would like to replace all lower-case letters that do not belong to
the functions "pmin" and "pmax" by 1 - toupper(...) to get
"pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
Assuming x is the input string:
gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"
--
Michael
http://www.dewey.myzen.co.uk
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.