On Fri, 29 Oct 2004, Sean Liang wrote: > Thanks for getting back to me. My situation is a bit more complicated. > I have a vector of sequences each of which might contain any number of a > given pattern (e.g. > > >pat=c("ATCGTTTGCTAC", "GGCTAATGCATTGC"); > > grep ("TGC", pat) > [1] 1 2 > > grep only tells me the position of first occurrence in each element > whereas the second element contains two "TGC"s.
sapply(strsplit(paste(1,pat,2, sep=""), "TGC"), length)-1 and you can also figure out the positions. You can also do it recursively with regexpr (on the same page as grep, no less). -- Brian D. Ripley, [EMAIL PROTECTED] 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 ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html