title: How can I convert these nested loops into an R loop function like sapply or tapply or
body: <p>I have this code which I run over a data frame t.</p>
  
  <pre><code>for (i in years){
      for (j in type){
              x &lt;- rbind(x, cbind(i, j, 
                         sum(t[(t$year == i) &amp; (t$type == j),]$Emissions, 
                             na.rm = TRUE)))
  }
  }
  </code></pre>
  
  <p>Basically, I have two vectors <code>years</code> and <code>type</code>. I'm finding the sum of each category and merging that into a data frame. The above code works, but I cannot figure out how to use one of the loop functions.</p>