dplyr group_by and mutate, how to access the data frame?
<p>When using dplyr's "group_by" and "mutate", if I understand correctly, the data frame is split in different sub-dataframes according to the group_by argument. For example, with the following code :</p>

<pre><code> set.seed(7)
 df &lt;- data.frame(x=runif(10),let=rep(letters[1:5],each=2))
 df %&gt;% group_by(let) %&gt;% mutate(mean.by.letter = mean(x))
</code></pre>

<p>mean() is applied successively to the column x of 5 sub-dfs corresponding to a letter between a &amp; e.</p>

<p>So you can manipulate the columns of the sub-dfs but can you access the sub-dfs themselves ? To my surprise, if I try : </p>

<pre><code> set.seed(7)
 data &lt;- data.frame(x=runif(10),let=rep(letters[1:5],each=2))
 data %&gt;% group_by(let) %&gt;% mutate(mean.by.letter = mean(.$x))
</code></pre>

<p>the result is different. From this result, one can infer that the "." df doesn't represent successively the sub-dfs but just the "data" one (the group_by function doens't change anything).<br>
The reason is that I want to use a stat function that take a data frame as an arguments on each of this sub-dfs.
Thanks !</p>