Re: [R] searching several subsequences in a single string sequence

2011-09-27 Thread Barry Rowlingson
On Tue, Sep 27, 2011 at 6:15 PM, Jean V Adams wrote: > For example, > > songs <- c("ABCABAABABABCAB", "ABACAB", "ABABCABCBC") > counts <- gregexpr("ABC", songs) > sapply(counts, length) That will still return '1' for the case where its not found, because of the -1. sapply(counts,function(x){su

Re: [R] searching several subsequences in a single string sequence

2011-09-27 Thread Jean V Adams
Barry Rowlingson wrote on 09/27/2011 12:06:21 PM: > > On Tue, Sep 27, 2011 at 5:51 PM, Marcelo Araya wrote: > > Hi all > > > > > > > > I am analyzing bird song element sequences. I would like to know how can I > > get how many times a given subsequence is found in single string sequence. > > >

Re: [R] searching several subsequences in a single string sequence

2011-09-27 Thread Barry Rowlingson
On Tue, Sep 27, 2011 at 5:51 PM, Marcelo Araya wrote: > Hi all > > > > I am analyzing bird song element sequences. I would like to know how can I > get how many times a given subsequence is found in single string sequence. > > > > > > For example: > > > > If I have this single sequence: > > > > AB

Re: [R] searching several subsequences in a single string sequence

2011-09-27 Thread Ivan Calandra
Hi Marcelo, Try this: x <- "ABCABAABABABCAB" length(gregexpr(pattern="ABC", x)[[1]]) See ?gregexpr for more details (though I admit that it is not easy to understand this help page) HTH, Ivan Le 9/27/2011 18:51, Marcelo Araya a écrit : Hi all I am analyzing bird song element sequences. I

[R] searching several subsequences in a single string sequence

2011-09-27 Thread Marcelo Araya
Hi all I am analyzing bird song element sequences. I would like to know how can I get how many times a given subsequence is found in single string sequence. For example: If I have this single sequence: ABCABAABABABCAB I am looking for the subsequence "ABC". Want I need to g