[R] overlapping pattern match
FMGCFMGC at terra.es
Fri Mar 28 23:26:44 CET 2003
try with this:
your.string <- "aaacdf"
nc1 <- nchar(your.string)-1
x <- unlist(strsplit(cadena, NULL))
x2 <- c()
for (i in 1:nc1)
x2 <- c(x2, paste(x2[i], x2[i+1], sep=""))
cat("ocurrences of <aa> in <your.string>:", length(grep("aa", x2)),
Hope it helps!
--- original message ---
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!
More information about the R-help