title: base R: Aggregate and sum by two columns
body: <p>I am trying to use aggregate function to achieve same result as with SQL query however:</p>
  
  <p>SQL: </p>
  
  <pre><code>sqldf(" SELECT
                  PhotoID,
                  UserID,
                  SUM(Points) AS PhotoTotalPoints
              FROM Photos
              GROUP BY PhotoId, UserId")
  116 186 rows.
  </code></pre>
  
  <p>R base:</p>
  
  <pre><code>aggregate(x = Photos["Points"]
    , by = Photos[c("PhotoId","UserId")]
    , FUN = sum
  )
  114 950 rows.
  </code></pre>
  
  <p>Using dplyr:</p>
  
  <pre><code>Photos %&gt;%
      group_by(PhotoId,UserId) %&gt;%
      summarise(sum = sum(Points)) 
  116 186 rows.
  </code></pre>
  
  <p>I am new to R. Tried to solve it in many ways but couldn't find any explanation in docs. What am I missing? </p>