Message-ID: <4EE21A6A.3070407@gmail.com>
Date: 2011-12-09T14:25:46Z
From: Duncan Murdoch
Subject: unexpected behaviour of sub() / usage of regexp
In-Reply-To: <1323440432.74951.YahooMailNeo@web28205.mail.ukl.yahoo.com>
On 09/12/2011 9:20 AM, Jannis wrote:
> Dear R users,
>
>
> the way I understand the documentation of sub() and regexp the following code:
>
>
>
> sub('[[:digit:]]{1,2}', '', '9ewww')
>
>
>
> ... should yield:
>
> 'ewww'
>
>
> It returns, however:
>
> 'www'
>
>
> Why is this the case? My code should just substitute 1 (minimum) or up to 2 (maximum) digits, i.e. numbers and not the 'e' in the string. Do I misinterpret something here?
I get your expected output of "ewww" running 2.14.0 or 2.14.0-patched on
Windows. So it's not a universal problem...
Duncan Murdoch
>
> Thanks for any ideas
> Jannis
>
>
> > sessionInfo()
> R version 2.14.0 (2011-10-31)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=C LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.