[R] overlapping pattern match
FMGCFMGC
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)),
sep="", fill=TRUE)
Hope it helps!
Fran
--- original message ---
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
More information about the R-help
mailing list