title: Error in dplyr when using nested group_by
body: <p>I´m trying to carry out several operations using dplyr but I´m stuck and I don´t know what I´m doing wrong.</p>
  <p>The first fifteen rows of my 60760 observations dataframe looks like this:</p>
  <pre><code>df &lt;-structure(list(dem_sect = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L),
  .Label = c(&quot;AB&quot;, &quot;EP&quot;, &quot;FE&quot;, &quot;MF&quot;, &quot;PA&quot;), class = &quot;factor&quot;), 
  area = c(1181.16, 1181.16, 2190.28, 2190.28, 956.08, 2190.28, 1181.16, 2190.28, 956.08, 2190.28, 2190.28, 1181.16, 2190.28, 956.08, 921.47), 
  peso_kg = c(0.184, 0.674, 0.1, 0.152, 0.21, 0.104, 4.31, 0.048, 0.242, 0.724, 0.126, 1.13, 0.13, 0.048, 0.075),
  sector = c(&quot;MFa&quot;, &quot;MFa&quot;, &quot;MFb&quot;, &quot;MFb&quot;, &quot;MFc&quot;, &quot;MFb&quot;, &quot;MFa&quot;, &quot;MFb&quot;, &quot;MFc&quot;, &quot;MFb&quot;, &quot;MFb&quot;, &quot;MFa&quot;, &quot;MFb&quot;, &quot;MFc&quot;, &quot;ABb&quot;)), 
  row.names = c(NA, 15L), class = data.frame&quot;) 
  </code></pre>
  <p>And here it is the code I´m working with</p>
  <pre><code>test &lt;- df %&gt;% 
  group_by(sector) %&gt;%
  summarise(md_area= mean (area),
            md_peso= mean (peso_kg),
            se_loc= sqrt(var(peso_kg))/sqrt(length (peso_kg)),
            cv_loc= sd(peso_kg)/ mean (peso_kg)*100) %&gt;%
  group_by(dem_sect) %&gt;%
  mutate(sum_sect = sum(SEloc * CVloc)))
  </code></pre>
  <p>Instead of <code>mutate(sum_sect = sum(SEloc * CVloc)</code>, I´ve tried using <code>mutate(sum_sect=sum(mean(area) * mean(peso_kg))</code> but in both cases I get the following error:</p>
  <blockquote>
  <p>Error in <code>group_by()</code>:
  ! Must group by variables found in <code>.data</code>.
  x Column <code>dem_sect</code> is not found.</p>
  </blockquote>
  <p>I tried several approaches but with no success. I don´t know what I´m doing wrong.
  Any hint will be more than welcome. Thanks in advance.</p>