Skip to content
Prev 374463 / 398513 Next

Discovering patterns in textual strings

Jeff:

The previous solution I sent you was hugely inefficient and frankly kind of
stupid. Here is a much better and simpler solution.
"abc_def",
       "abc.def",
       "abc def",
       "abcd_ef",
       "abcd",
       "e","f")

## Create vector of patterns of same length as z, many of which are repeated
## Now can use tapply() to get indices if desired
## Note that the patterns label the groups
$abc
[1] 1 2 3 4

$abcd
[1] 5 6

$e
[1] 7

$f
[1] 8

No need to reply.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sat, May 5, 2018 at 12:14 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: