Q:

Finding and counting repeated occurrences

I wish to make a function, which will accept three arguments (starting position, ending position, length), and by that function, I wish to find out, how many times each of the different pattern of that particular length appear and then I wish to extract the maximum one. Sounds confusing. 

A:

Try this:
    countSubstring<-function(string,start,end,len) {
      startChar<-seq(start,end,by=len)
      table(substring(string,startChar,startChar+(len-1)))
    }

    string<-"aabaaaabaaaacaaaabaaaabaa"

    countSubstring(string,start=1,end=15,len=5)

     aabaa aacaa 
       2     1

