title: Summarizing a dataframe using a reference column
body: <p>Consider the following dataframe:</p>
  <pre><code>df &lt;- data.frame(waypoint = 1:10, pnt1 = NA, pnt2 = NA, pnt3 = NA)
  
  x &lt;- c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;)
  
  df$pnt1 &lt;- as.factor(sample(x, 10, replace = T))
  df$pnt2 &lt;- as.factor(sample(x, 10, replace = T))
  df$pnt3 &lt;- as.factor(sample(x, 10, replace = T))
  
  df
  </code></pre>
  <p>I'd like to summarize this dataframe in the following manner, where the values from the &quot;pnt1, pnt2, and pnt3&quot; columns in the original df are summed for each waypoint and placed into new columns &quot;A, B, C, D&quot;. The shell of the result would look like this:</p>
  <pre><code>df2 &lt;- data.frame(waypoint = 1:10, A = NA, B = NA, C = NA, D = NA)
  </code></pre>
  <p>How can I code this to produce a result similar to df2 that is filled with the correct values?</p>