title: What is the equivalent of the SumIf function in R
body: <p>I am new to R and this site, but I searched and didn't find the answer I was looking for.</p>
  
  <p>If I have the following data set "total":</p>
  
  <pre><code>names &lt;- c("a", "b", "c", "d", "a", "b", "c", "d")
  x &lt;- cbind(x1 = 3, x2 = c(3:10))
  total &lt;- data.frame(names, x)
  total
  
    names x1 x2
  1     a  3  3
  2     b  3  4
  3     c  3  5
  4     d  3  6
  5     a  3  7
  6     b  3  8
  7     c  3  9
  8     d  3  10
  </code></pre>
  
  <p>How can I create a new data set that works like the SumIf Excel function with just unique rows?</p>
  
  <p>The answer should be a new data set "summary" that is 4 x 3.</p>
  
  <pre><code>names &lt;- unique(names)
  summary &lt;- data.frame(names)
  summary$Sumx1 &lt;- ?????
  summary$Sumx2 &lt;- ?????
  summary
  
   names Sumx1 Sumx2
  1  a     6    10
  2  b     6    12
  3  c     6    14
  4  d     6    16
  </code></pre>