[R] overlapping pattern match

Jerome Asselin jerome at hivnet.ubc.ca
Fri Mar 28 19:33:31 CET 2003

Here's a way.

string <- "aaacdf"
pattern <- "aa"
nstring <- nchar(string)
npattern <- nchar(pattern)
stringlist <- substring(string, 1:(nstring-npattern+1), npattern:nstring)

Also, have a look at: pmatch, charmatch, grep, sub, gsub, regexpr, chartr. I 
couldn't find a simple function to do what you want.

Hope this helps.


On March 27, 2003 05:34 pm, Yiping Fan wrote:
> Content-Length: 360
> Status: R
> X-Status: N
> Hi, all,
>      I have a string like  "aaacdf",  I want to find how many "aa" in the
> string. Obviously, It is 2 in this case.  it is easy to do in Perl, but how
> to do such  overlapping match in R or Splus.  Thanks!
> Y.Fan
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

More information about the R-help mailing list