Message-ID: <CAM_vjunUs6C=DCzCvyhfZsi=68Xtq1PQF7549FSSq=rVe9EvAw@mail.gmail.com>
Date: 2011-09-19T11:05:07Z
From: Sarah Goslee
Subject: text matching
In-Reply-To: <21705481E9E944A8AD5BF3913B9DE685@primpsg>
Hi,
On Mon, Sep 19, 2011 at 6:15 AM, SNV Krishna <krishna at primps.com.sg> wrote:
> Hi All,
>
> I have a character vector by name tickers
>
>> head(tickers,10)
>
> ? ? ? ? ? ?V1
> 1 ?ADARSHPL.BO
> 2 ? ? ? ?AGR.V
> 3 ? ? ? ? ?AGU
> 4 ? ? ? AGU.TO
> 5 ? ? AIMCO.BO
> 6 ?ALUFLUOR.BO
> 7 ? ? ? ?AMZ.V
> 8 ? ? ? ? ?AVD
> 9 ?ANILPROD.BO
> 10 ? ?ARIES.BO
>
> I would like to extract all elements that has ".BO" in it. I tried
>
>> grep("\.BO",tickers)
> Error: '\.' is an unrecognized escape in character string starting "\."
You need instead:
> tickers <- c("A.BO", "BOB", "C.BO")
> grep("\\.BO", tickers)
[1] 1 3
>
> tickers[grep("\\.BO", tickers)]
[1] "A.BO" "C.BO"
>> grep(".BO",tickers)
> [1] 1
That's odd; it should have returned many more matches. You may need to
check the format of your data.
> Could any one please guide me on this. Many thanks for the help
>
> Best Regards,
>
> Krishna
>
--
Sarah Goslee
http://www.functionaldiversity.org