title: Creating a summary row for each group in a dataframe based on other variables in the group
body: <p>Fairly new to R, ended up in the following situation: I want to create a summary row for each group in the dataframe based on <code>Year</code> and <code>Model</code>, where a <code>value</code> of each row would be based on the subtraction of <code>value</code> of one <code>Variable</code> from others in the group.</p>
  <pre><code>df &lt;- data.frame(Model = c(1,1,1,2,2,2,2,2,2,2,2,2,2),
               Year = c(2020, 2020, 2020, 2020, 2020, 2020, 2020, 2030, 2030, 2030, 2040, 2040, 2040),
               Variable = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;A&quot;, &quot;C&quot;, &quot;E&quot;, &quot;A&quot;, &quot;C&quot;, &quot;D&quot;),
               value = c(15, 2, 5, 25, 6, 4, 4, 41, 24,1, 15, 3, 2))
  </code></pre>
  <p>I have managed to create a new row for each group, so it already has a <code>Year</code> and a <code>Variable</code> name that I manually specified using:</p>
  <pre><code>df &lt;- df %&gt;% group_by(Model, Year) %&gt;% group_modify(~ add_row(., Variable = &quot;New&quot;, .before=0))
  </code></pre>
  <p>However, I am struggling to create an equation from which I want to calculate the <code>value</code>.</p>
  <p><strong>What I want to have instead of NAs:</strong> <code>value</code> of A-B-D in each group</p>
  <p><em>Would appreciate any help. My first thread here, pardon for any inconvenience.</em></p>