title: Efficient way to cbind list by groups in data.table
body: <p>I have a data.frame </p>
  
  <p><strong>data</strong></p>
  
  <pre><code>data = structure(list(mystring = c("AASDAASADDLKJLKADDLKKLLKJLJADDLJLKJLADLKLADD", 
      "ASDSDFJSKADDKJSJKDFKSADDLKJFLAK"), class = c("cat", "dog")), .Names = c("mystring", 
      "class"), row.names = c(NA, -2L), class = "data.frame")
  </code></pre>
  
  <p>which looks like</p>
  
  <pre><code>#&gt; dtt1
  #                                      mystring class
  #1 AASDAASADDLKJLKADDLKKLLKJLJADDLJLKJLADLKLADD   cat
  #2              ASDSDFJSKADDKJSJKDFKSADDLKJFLAK   dog
  </code></pre>
  
  <p>I am searching the start and end positions of a pattern "ADD" with in the first 20 characters in the strings under <code>mystring</code> considering <code>class</code> as the group.</p>
  
  <p>I am doing this using <code>str_locate</code> of <code>stringr</code> package. Here is my attempt</p>
  
  <pre><code>setDT(dtt1)[, 
  cbind(list(str_locate_all(substr(as.character(mystring), 1, 20),"ADD")[[1]][,1]),
        list(str_locate_all(substr(as.character(mystring), 1, 20),"ADD")[[1]][,2])), 
        by = class]
  </code></pre>
  
  <p>This gives my <strong>desired output</strong></p>
  
  <pre><code>#   class V1 V2
  #1:   cat  8 10
  #2:   cat 16 18
  #3:   dog 10 12
  </code></pre>
  
  <p><strong>Question</strong>: 
  I would like to know if this is a standard approach or this can be done in a more efficient manner. <code>str_locate</code> gives the <code>start</code> and <code>end</code> positions of the matched pattern in separate columns, and I am putting them in separate list to <code>cbind</code> them together with the <code>data.table</code>? Also how can I specify the <code>colnames</code> for the cbinded <code>columns</code> here?</p>