On Jun 2, 2011, at 4:21 PM, Ben Ganzfried wrote:
> Thank you very much for your help. It saved me a lot of time and it
> worked perfectly. I have a quick follow-up as I'm not sure I
> understand yet why the code works and where it comes from.
>
> For example, in: Tstg <- sub(".*T(\\d)N.", "
Thank you very much for your help. It saved me a lot of time and it worked
perfectly. I have a quick follow-up as I'm not sure I understand yet why
the code works and where it comes from.
For example, in: Tstg <- sub(".*T(\\d)N.", "\\1", tmp)
*How exactly does the substitution operation work?
On Jun 2, 2011, at 2:54 PM, Ben Ganzfried wrote:
Hi,
First of all, I would like to introduce myself as I will probably
have many
questions over the next few weeks and want to thank you guys in
advance for
your help. I'm a cancer researcher and I need to learn R to
complete a few
projec
On Jan 7, 2010, at 2:47 PM, Mark Kimpel wrote:
I have an example where escaping "." does not seem to be behaving
consistently, but perhaps it is due to my misunderstanding. Could
someone
explain to me why the below produces the output it does?
It seems to me that in the second example, wher
I have an example where escaping "." does not seem to be behaving
consistently, but perhaps it is due to my misunderstanding. Could someone
explain to me why the below produces the output it does?
It seems to me that in the second example, where I am being more precise
about specifying that a "."
Here's what I came up with:
> gsub("(\\w)[^ ]+[\\b ]", "\\1", astr)
[1] "Timtowtdit"
You might be interested in Regular Expressions Cookbook from O'Reilly
(publisher not author) or http://www.regular-expressions.info/
I usually bumble along knowing there are better ways to do whatever I am doing
ult can be
used to subscript avec.
Best regards,
Chuck Taylor
TIBCO Spotfire
Seattle, WA, USA
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of ravi
Sent: Tuesday, August 04, 2009 10:28 AM
To: r-help@r-project.org
Subject: [R] regex
And here is a second way:
> strapply(astr, "(\\w)\\w+", c, simplify = c)
[1] "T" "i" "m" "t" "o" "w" "t" "d" "i" "i" "t" "f" "f" "T"
On Tue, Aug 4, 2009 at 1:42 PM, Gabor
Grothendieck wrote:
> Try this:
>
>> library(gsubfn)
>> strapply(astr, "\\w+", ~ substr(x, 1, 1), simplify = c)
> [1] "T" "
Try this:
> library(gsubfn)
> strapply(astr, "\\w+", ~ substr(x, 1, 1), simplify = c)
[1] "T" "i" "m" "t" "o" "w" "t" "d" "i" "i" "t" "f" "f" "T"
On Tue, Aug 4, 2009 at 1:28 PM, ravi wrote:
>
> Hi,
> I am getting stuck over an apparently simple problem in the use of regular
> expressions :
> T
Hi,
I am getting stuck over an apparently simple problem in the use of regular
expressions :
To collect together the first letters of the words from the Perl motto, “There
is more than one way to do it” in the following form – TIMTOWTDI.
I tried the following code :
# A regex problem with
Tan, Richard wrote:
> Sorry I did not give some examples in my previous posting to make my
> question clear. It's not exactly 1 digit, but at least one digit. Here
> are some examples:
>
>
>> input = c(none='0foo f0oo foo0 foofoofoo0 0foofoofoo TOOL9NGG
>>
> NONUMBER',all='foob0 fo0o0
e-
From: Wacek Kusnierczyk [mailto:waclaw.marcin.kusnierc...@idi.ntnu.no]
Sent: Tuesday, June 09, 2009 1:06 PM
To: Greg Snow
Cc: Marc Schwartz; Barry Rowlingson; r-help@r-project.org; Tan, Richard
Subject: Re: [R] Regex question to find a string that contains 5-9
alpha-numeric characters, at least one of
Greg Snow wrote:
> Here is one way using a single pattern (so can be used in a substitution), it
> uses Perl's positive look ahead patters:
>
>
>> test <-
>> c("SHRT","5HRT","M1TCH","M1TCH5","LONG3RS","NONUMBER","TOOLNGG","ooops.3")
>>
>> sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'xxx
ps.3"
>
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Marc Schwartz
> Sent: Monday, J
Wacek Kusnierczyk wrote:
> Marc Schwartz wrote:
>
>> On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote:
>>
>>
>>> On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard wrote:
>>>
Hi,
This is not exactly an R question but I am trying to use gsub to
replace
a string t
Marc Schwartz wrote:
>
> On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote:
>
>> On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard wrote:
>>> Hi,
>>>
>>> This is not exactly an R question but I am trying to use gsub to
>>> replace
>>> a string that contains 5-9 alpha-numeric characters, at least one o
On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote:
On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard
wrote:
Hi,
This is not exactly an R question but I am trying to use gsub to
replace
a string that contains 5-9 alpha-numeric characters, at least one of
which is a number. Is there a good wa
On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard wrote:
> Hi,
>
> This is not exactly an R question but I am trying to use gsub to replace
> a string that contains 5-9 alpha-numeric characters, at least one of
> which is a number. Is there a good way to write it in a one line regex?
The only way I
Hi,
This is not exactly an R question but I am trying to use gsub to replace
a string that contains 5-9 alpha-numeric characters, at least one of
which is a number. Is there a good way to write it in a one line regex?
Thanks,
Richard
__
R-help@r-proj
[EMAIL PROTECTED] wrote:
Hi: Gabor's solution does do it in a single line. he just used paste to
make the line. see below. John's is sort of a single line also but he
called sub twice.
I doubt that it's possible to make it shorter than those solutions.
Well, you can lose the parentheses and
; ]+$)"
sub(right, "", sub(left, "", varReg))
[1] "this is my text"
I hope this helps,
John
--
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
-Original Mess
--
> John Fox, Professor
> Department of Sociology
> McMaster University
> Hamilton, Ontario, Canada
> web: socserv.mcmaster.ca/jfox
>
>
>> -Original Message-
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On
>> Behalf Of Ferry
>&g
uot;this is my text"
I hope this helps,
John
--
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On
> Be
If patReg1 and patReg2 are your two regex's then:
gsub(paste(patReg1, patReg2, sep = "|"), "", varReg)
On Mon, Nov 3, 2008 at 8:37 PM, Ferry <[EMAIL PROTECTED]> wrote:
> hello,
>
> i am trying to extract text using regex as follows:
>
> "* < <* this is my text > > "
>
> into:
>
> "this is my
hello,
i am trying to extract text using regex as follows:
"* < <* this is my text > > "
into:
"this is my text"
below what I did:
varReg <- "* < <* this is my text > > "
## either this pattern
patReg <- "(^[ <*]+)"
## or below patten
patReg <- "([ > ]+$)"
sub(patReg, '', varReg)
dependi
25 matches
Mail list logo