title: Creating a dataframe based on multiple columns of a data.frame or data.table
body: <p>I have a data.table that looks like this:</p>
  
  <pre><code>      V1    V2          V3    V4
    4: ASW NA19704-200-37 SVLEN  0
    5: ASW NA19834-200-37 SVLEN  0                          
  301: YRI    GS000017413 SVLEN  0
  302: YRI    GS000017898 SVLEN  0
  303: YRI    GS000018623 SVLEN  0
  </code></pre>
  
  <p>I also have this in a data frame. I want to sum V4 for all columns in which V1 AND V3 have the same values.</p>
  
  <p>V1 has 5 values, and V3 has 24, all of which are strings, but I can convert them to factors or whatever else.</p>
  
  <p>The statement:</p>
  
  <pre><code>chr10pos53400000dt[chr10pos53400000dt$V3=="CDS",sum(V4),by=V1]
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>      V1  V1
  1:   ASW   9
  2:   CEU  68
  3: Lupus 109
  4:    RA 160
  5:   YRI 163
  </code></pre>
  
  <p>Which is what it should return. </p>
  
  <p>Only now, I wish to do this for ALL values in V3. To do this I made a vector called "ComponentList" via the command <code>ComponentList=unique(chr10pos53400000dt$V3)</code>.</p>
  
  <p>The statement <code>for (i in ComponentList) {ByComponent[i]&lt;-chr10pos53400000dt[chr10pos53400000dt$V3==ComponentList[i],sum(V4),by=V1]}</code> issues 24 error messages (same as the length of <code>ComponentList</code>) saying </p>
  
  <pre><code>24: In `[&lt;-.data.frame`(`*tmp*`, i, value = structure(list( ... :
  provided 2 variables to replace 1 variables 
  </code></pre>
  
  <p>Does anyone know how I can fill a new data frame with the results like those above, but iteratively?? </p>
  
  <p>Thank you very much!</p>