Good morning Steve. Terrific, so kind of you to follow-up.

I will add that to my ever growing R bag of tips and tricks.

Cheers.

WHP

William H. Poling, Ph.D., MPH | Manager, Revenue Development
Data Intelligence & Analytics
Zelis Healthcare


-----Original Message-----
From: S Ellison <s.elli...@lgcgroup.com>
Sent: Monday, March 18, 2019 8:32 AM
To: Bill Poling <bill.pol...@zelis.com>; r-help (r-help@r-project.org) 
<r-help@r-project.org>
Subject: RE: Help with gsub function

> tb2a$TID2 <- gsub(tb2a$TID, pattern="-[0-0]{0,7}", replacement = "")

Just to add something on why this didn't work ...

It looks like you were trying to match a hyphen followed by a number up to 
seven digits. by mistake(?) you gave the digit range as [0-0] so it would 
repmatch a hyphen followed by between none and seven zeroes. When it met "-0" 
it matched that.
And because it was gsub, it replaced what it matched.
If you'd given it the right digit range it would have replaced the whole of the 
number.

If you _really_ wanted to do that kind of thing (control the following 
pattern), you'd have needed something like (untested) gsub("-([0-0]{0,7})", 
"\\1", tb2a$TID)

#The () means 'remember this bit"; the "\\1" means "put the first thing you 
remember here". And it needs to be "\\1" because that becomes "\1" for the grep 
parser.


Steve E


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:22}}

______________________________________________
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.

Reply via email to