s-news
[Top] [All Lists]

Re: match functionality

To: "Leeds, Mark" <mleeds@mlp.com>
Subject: Re: match functionality
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Thu, 28 Aug 2003 18:44:09 +0100 (BST)
Cc: s-news@wubios.wustl.edu
In-reply-to: <C497480353EF904FBF7A8B0851E5422CCB5591@MAIL002.AD.MLP.COM>
What does `show up in' mean?  There are lots of subtle variations.

For an exact match try sum(instring == instringector).
For inclusion try length(grep(instring, instringector), but you would 
need to escape e.g. .[]{}()*\^$ in instring.  You could anchor the match 
to the beginning ....  (grep on old Windows versions of S-PLUS wasn't a 
grep at all.)

On Thu, 28 Aug 2003, Leeds, Mark wrote:

> i have a character string and i am trying
> to find out how many times that
> character string shows
> up in another vector of character strings.
>  
> unfortunately, match doesn't
> do what i want because if i do
>  
> stringindex_pmatch(instring,instringector)

That's some of the hardest-to-read code I've seen for a while but it 
seems to be using pmatch(), not match().  (And there is also charmatch.)
The use of _ for assignment is deprecated (in S-PLUS 6.1, for example).
Did you have trouble reading it too?  (It took me several looks to spot 
the discrepancy.)

> stringindex only returns the first occurrence.
>  
> is there some other function that does
> what i need ? i can't find one.
> i guess i could write
> something but my guess is
> that it exists already.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>