Gabor Grothendieck ggrothendieck at 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
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 character
Try this:
gsub(^(\\w*).*$, \\1, x)
On Wed, May 13, 2009 at 8:41 PM, Stephen J. Barr stephenjb...@gmail.comwrote:
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
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
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)
Ted.
On Wed, May 13,
: 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 regular expression. However, I am
having trouble getting this to work
6 matches
Mail list logo