Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.64.1012041842370.25614@tajo.ucsd.edu>
Date: 2010-12-05T02:50:19Z
From: Charles C. Berry
Subject: grep for strings
In-Reply-To: <AANLkTinYPp2OfGuKUHxsxV_PJv+urnKZjbm9edBTf6CE@mail.gmail.com>

On Sun, 5 Dec 2010, Santosh Srinivas wrote:

> I am trying to find the function where I can search for a pattern in a
> text string (I thought I could use grep for this but no :().

Correct, but reading

 	?grep

and running

 	example( grep )

should show you how to do that search.

>
>> x
> [1] "abcdefghijkl"
>
> I want to find the positions (i.e. equivalent of nchar) for "cd" and
> in case there are multiple hits .. then the results as a array

You will need to deal with the possibility that there are more 'cd's in 
some elements of 'text' than in others.

So, it is not obvious that an _array_ will work without some special 
tooling.

HTH,

Chuck



>
> Thank you.
>
> ______________________________________________
> 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.
>

Charles C. Berry                            Dept of Family/Preventive Medicine
cberry at tajo.ucsd.edu			    UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901