title: How to group in R and return as a list?
body: <p>I would like to organise a data frame by the contents of three of its columns from a total of 6 columns (a minimal example of just the three below) and have each unique cluster of similarity (over those 3 columns) returned as a subsetted data frame structure inside a list. So I basically chop the dataframe up into smaller data frame and put into a list. </p>
  
  <pre><code>var1 &lt;- "erg11"
  var2 &lt;- "cyp51"
  df &lt;- data.frame(primerID=c(1,2,3,2,4,3,2,1,1,1,2),geneName=c(var1,var1,var2,var1,var1,var2,var2,var2,var1,var2,var1),insertLength=c(111,111,81,81,81,111,102,111,81,81,102))
  </code></pre>
  
  <p>Given my old C background I tried nested for loops, subsetting the data frame when all three elements of the data frame were found in three lists e.g., </p>
  
  <pre><code>Alist &lt;- as.list(unique(df$primerID))
  Blist &lt;- as.list(unique(df$geneName))
  Clist &lt;- as.list(unique(df$insertLength))
  
  uniqueCounter &lt;- 1
  uniqueList &lt;- list()
  
  for(i in 1:length(Alist)) {
    for(k in 1:length(Blist)) {
      for(n in 1:length(Clist)) {
        indDF &lt;- subset(df, df$primerID %in% Alist[i] &amp; df$geneName %in% Blist[j] &amp; df$insertLength %in% Clist[n])
        if(nrow(indDF) &gt; 0) {
          uniqueList[uniqueCounter] &lt;- indDF
          uniqueCounter &lt;- uniqueCounter + 1
        }
      }
    }
  }
  </code></pre>
  
  <p>However, this takes most of the night to run. </p>
  
  <p>Thanks</p>