title: How do I safely remove duplication after using a group_by and summarise?
body: <pre><code>    test_df &lt;- tibble(
    Project = c(&quot;Project 1&quot;,&quot;Project 1&quot;,&quot;Project 2&quot;,&quot;Project 3&quot;,&quot;Project 3&quot;,&quot;Project 3&quot;),
    Cost = c(100,50,400,50,75,150),
    `Percent Over Cost` = c(.25,.25,.14,.05,.05,.05)
  )
  </code></pre>
  <p>Here is what the data frame above looks like:</p>
  <p><a href="https://i.stack.imgur.com/I5rgf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I5rgf.png" alt="Visual " /></a></p>
  <p>I am trying to reduce the duplication in my data frame. Basically, there are three variables of interest: Project, Cost, and Percent over Cost. What I want to do is sum the Costs. So, for instance, Project 1 should have a Cost of 150. But I don't want to sum the percentages. So my ideal data frame should have three rows: one for Project 1, one for Project 2, and one for Project 3, with the Cost column summed by Project, and the Percentage unsummed.</p>
  <p>I am trying to reduce the duplication in my data frame. Basically, there are three variables of interest: Project, Cost, and Percent over Cost. What I want to do is sum the Costs. So, for instance, Project 1 should have a Cost of 150. But I don't want to sum the percentages. So my ideal data frame should have three rows: one for Project 1, one for Project 2, and one for Project 3, with the Cost column summed by Project, and the Percentage unsummed.</p>
  <p>The below code sums the numbers but leaves duplication in the Projects. See the image below.</p>
  <pre><code>test_df %&gt;% 
    group_by(Project) %&gt;% 
    summarise(
      Project,
      `Percent Over Cost`,
      Cost = sum(Cost)
    )
  </code></pre>
  <p>This is what the code returns.</p>
  <p><a href="https://i.stack.imgur.com/Pfa3X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pfa3X.png" alt="enter image description here" /></a></p>
  <p>If I use the unique() function on the resulting data frame, I can get what I want... but I'm just unsure if that's bad practice. I'm nervous to use that approach of my company's data. Can anyone advise if there's a better way to approach this?</p>