Gabor Grothendieck gmail.com> writes:
>
> R interprets backslash to give special meaning to the next character, i.e.
> it strips off the backslash and send the following character to gsub
> possibly reinterpreting it specially (for example \n is newline). Thus
> a backslash will never get to gs
-help-boun...@r-project.org] On
Behalf Of Stephen J. Barr
Sent: Thursday, 14 May 2009 9:42 AM
To: r-help@r-project.org
Subject: [R] matching period with perl regular expression
Hello,
I have several strings where I am trying to eliminate the period and
everything after the period, using a regu
On 13-May-09 23:47:41, Henrique Dallazuanna wrote:
> Try this:
>
> gsub("^(\\w*).*$", "\\1", x)
Even simpler:
x
# [1] "wa.w"
gsub("\\..*","",x,perl=TRUE)
# [1] "wa"
x<-"abcde.fghij.klmno"
gsub("\\..*","",x,perl=TRUE)
# [1] "abcde"
(and it doesn't matter whether 'perl' is TRUE or FALSE)
R interprets backslash to give special meaning to the next character, i.e.
it strips off the backslash and send the following character to gsub
possibly reinterpreting it specially (for example \n is newline). Thus
a backslash will never get to gsub unless you use a double backslash.
Thus we can u
Try this:
gsub("^(\\w*).*$", "\\1", x)
On Wed, May 13, 2009 at 8:41 PM, Stephen J. Barr wrote:
> Hello,
>
> I have several strings where I am trying to eliminate the period and
> everything after the period, using a regular expression. However, I am
> having trouble getting this to work.
>
> > x
Hello,
I have several strings where I am trying to eliminate the period and
everything after the period, using a regular expression. However, I am
having trouble getting this to work.
> x = "wa.w"
> gsub(x, "\..*", "", perl=TRUE)
[1] ""
Warning messages:
1: '\.' is an unrecognized escape in a cha
6 matches
Mail list logo