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
De
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
__
R-help@r-project.or
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 Be
There are many ways, Rolf. You need to look into the syntax of regular
expressions. It depends on how sure you are that the formats are exactly as
needed. Escaping the period with one or more backslashes is one way. Using
string functions is another.
Suggestion. See if you can make a regular expre
> 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 PM
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, wrote:
> You
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, 20
> 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
> ,THETA3 ,THET
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] "SIG
Thanks guys. I've pulled my O'Reilly book and will begin reviewing it.
Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine
15032 Hunter Court, Westfield, IN 46074
(317) 490-5129 Work, & M
2009 9:28 AM
To: William Dunlap; r-help@r-project.org
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.
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 to do is delete
an arbitrary number of characters, including brackets and parens enclosing
them
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 insta
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 Kimpel wrote:
> I'm having trouble achieving the resul
14 matches
Mail list logo