On Tue, 9 Feb 2021 17:34:00 +1300
Rolf Turner wrote:
>
> David Wolfskill's post solved my problem perfectly. Thanks.
>
> Thanks also to Bert Gunter and Avi Gross.
Whoops. David Wolfskill's message came to me off-list.
Sorry for the confusion.
cheers,
Rolf
--
Honorary Research Fellow
David Wolfskill's post solved my problem perfectly. Thanks.
Thanks also to Bert Gunter and Avi Gross.
cheers,
Rolf
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
__
Simpler, but would fail if there are more "."s beyond the second (it
changes the last one to a "-"):
> sub("(.*)\\.([^.]*)", "\\1-\\2", "aa.bcv.cdg")
[1] "aa.bcv-cdg"
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka
second time starting just past it.
Then replace. Fairly straightforward and very possibly much faster.
-Original Message-
From: R-help On Behalf Of Rolf Turner
Sent: Monday, February 8, 2021 9:29 PM
To: "r-help@R-project.org" "@r-project.org
Subject: [R] Help with regular express
> gsub("(.*\\.[^.]*)\\.(.*)","\\1-\\2", "aa.bcv.cdg")
[1] "aa.bcv-cdg"
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Feb 8, 2021 at 6:29
I want to deal with strings of the form "a.b.c" and to change (using
sub() or whatever is appropriate) the second "." to a "-", i.e. to
change "a.b.c" to "a.b-c". I want to leave the first "." as-is.
I guess I could do a gsub(), changing all "."s to "-"s, and then do
a sub() changing the first
I think I would replace all , with . and subsequently replace all first .
with , using ^\\.
x <- gsub(",", ".", x)
gsub("^\\.", ",", x)
It's not so elegant, but it is easier to understand than backreferences and
complex regex.
Best,
Ulrik
On Tue, 13 Feb 2018, 03:38 Boris Steipe,
You can either use positive lookahead/lookbehind - but support for that is a
bit flaky. Or write a proper regex, and use
backreferences to keep what you need.
R > x <- "abc 1,1 ,1 1, x,y 2,3 "
R > gsub("(\\d),(\\d)", "\\1.\\2", x, perl = TRUE)
[1] "abc 1.1 ,1 1, x,y 2.3 "
B.
> On Feb 12,
> On Feb 12, 2018, at 6:22 PM, Dennis Fisher wrote:
>
> R 3.4.2
> OS X
>
> Colleagues
>
> I would appreciate some help with regular expressions.
>
> I have string that looks like:
> " ITERATION ,THETA1 ,THETA2
>
Hi Dennis,
How about:
# define the two values to search for
x<-2
y<-3
# create your search string and replacement string
repstring<-paste(x,y,sep=",")
newstring<-paste(x,y,sep=".")
# this is the string that you want to change
thetastring<-"SIGMA(2,3)"
sub(repstring,newstring,thetastring)
[1]
R 3.4.2
OS X
Colleagues
I would appreciate some help with regular expressions.
I have string that looks like:
" ITERATION ,THETA1 ,THETA2
,THETA3 ,THETA4 ,THETA5
,THETA6
I'm having trouble achieving the results I want using a regular expression.
I want to eliminate all characters that fall within square brackets as well
as the brackets themselves, returning an . I'm not sure if it's R's use of
double slash escapes or something else that is tripping me up. If I
How about this:
myCharVec - c([the rain in spain], (the rain in spain))
gsub('\\[.*\\]', '', myCharVec)
[1] (the rain in spain)
you had *. when you should have .*
On Thu, Aug 20, 2009 at 11:30 AM, Mark Kimpelmwkim...@gmail.com wrote:
I'm having trouble achieving the
Mark,
Try this:
myCharVec
[1] [the rain in spain] (the rain in spain)
gsub(\\[.*\\], , myCharVec)
[1] (the rain in spain)
You need two backslashes to escape the square brackets. The regular
expression \\[.\\] translates to a [ followed by 0 or more instances
of any
: Thursday, August 20, 2009 8:31 AM
To: r-help@r-project.org
Subject: [R] help with regular expressions in R
...
myCharVec - c([the rain in spain], (the rain in spain))
gsub('\\[*.\\]', '', myCharVec)
Change the '*.' to '.*'.
Your expression matches 0 or more left square brackets
Subject: Re: [R] help with regular expressions in R
Well, I guess I'm not quite there yet. What I gave earlier was a
simplified example, and did not accurately reflect the complexity of the
task.
This is my real world example. As you can see, what I need
-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Mark Kimpel
Sent: Thursday, August 20, 2009 8:31 AM
To: r-help@r-project.org
Subject: [R] help with regular expressions in R
...
myCharVec - c([the rain in spain], (the rain in spain))
gsub('\\[*.\\]', '', myCharVec
17 matches
Mail list logo