<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/dplyr-do-some-tips-for-using-and-programming/"></div></div><div><a data-url="http://www.r-bloggers.com/dplyr-do-some-tips-for-using-and-programming/" data-counturl="http://www.r-bloggers.com/dplyr-do-some-tips-for-using-and-programming/" data-count="horizontal" data-text="dplyr do: Some Tips for Using and Programming" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.milanor.net/blog/dplyr-do-tips-for-using-and-programming/"> MilanoR</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<div>
<p><em>This post was originally posted on Quantide blog – <a target="_blank" href="http://www.quantide.com/website/dplyr-do-tips-using-programming/">see here</a>.</em></p>
<p>If you want to compute arbitrary operations on a data frame returning more than one number back, use <strong><code>dplyr</code> <code>do()</code></strong>!</p>
</div>
<p>This post aims to explore some basic concepts of <code>do()</code>, along with giving some advice in using and programming.</p>
<p><code>do()</code> is a verb (function) of <code>dplyr</code>. <code>dplyr</code> is a powerful R package for data manipulation, written and maintained by Hadley Wickham. This package allows you to perform the common data manipulation tasks on data frames, like: filtering for rows, selecting specific columns, re-ordering rows, adding new columns, summarizing data and computing arbitrary operations.</p>
<p>First of all, you have to install <code>dplyr</code> package:</p>
<pre>install.packages(&quot;dplyr&quot;)</pre>
<p>and to load it:</p>
<pre>require(dplyr)</pre>
<p>We will analyze the use of <code>do()</code> with the following dataset, created with random data:</p>
<pre>set.seed(100)
ds &lt;- data.frame(group=c(rep(&quot;a&quot;,100), rep(&quot;b&quot;,100), rep(&quot;c&quot;,100)), 
                 x=rnorm(n = 300, mean = 3, sd = 2), y=rnorm(n = 300, mean = 2, sd = 2))</pre>
<p>We firstly transform it into a <code>tbl_df</code> object to achieve a better print method. No changes occur on the input data frame.</p>
<pre>ds &lt;- tbl_df(ds)
ds</pre>
<pre>Source: local data frame [300 x 3]

    group        x           y
   (fctr)    (dbl)       (dbl)
1       a 1.995615 -1.71089045
2       a 3.263062 -0.03712943
3       a 2.842166 -0.09022217
4       a 4.773570  0.69742469
5       a 3.233943  2.76536531
6       a 3.637260  4.06379942
7       a 1.836419  2.26214995
8       a 4.429065  2.75438347
9       a 1.349481 -1.77539016
10      a 2.280276  3.04043881
..    ...      ...         ...</pre>
<div>
<h2>Base Concepts of do() (Non Standard Evaluation Version)</h2>
<p>As we already said, <code>do()</code> computes arbitrary operations on a data frame returning more than one number back.</p>
<p>To use <code>do()</code>, you must know that:</p>
<ul>
<li>it always <strong>returns a dataframe</strong></li>
<li>unlike the others data manipulation verbs of <code>dplyr</code>, <code>do()</code> needs the specification of <strong><code>.</code></strong> placeholder inside the function to apply, referring to the data it has to work with.
<pre># Head of ds
ds %>% do(head(.))</pre>
<p> </p>
<pre>Source: local data frame [6 x 3]

   group        x           y
  (fctr)    (dbl)       (dbl)
1      a 1.995615 -1.71089045
2      a 3.263062 -0.03712943
3      a 2.842166 -0.09022217
4      a 4.773570  0.69742469
5      a 3.233943  2.76536531
6      a 3.637260  4.06379942</pre>
</li>
<li>it is conceived to be used with dplyr <strong><code>group_by()</code></strong> to compute operations within groups:
<pre># Head of ds by group
ds %>% group_by(group) %>% do(head(.))</pre>
<p> </p>
<pre>Source: local data frame [18 x 3]
Groups: group [3]

    group          x           y
   (fctr)      (dbl)       (dbl)
1       a 1.99561530 -1.71089045
2       a 3.26306233 -0.03712943
3       a 2.84216582 -0.09022217
4       a 4.77356962  0.69742469
5       a 3.23394254  2.76536531
6       a 3.63726018  4.06379942
7       b 2.33415330 -0.56965729
8       b 5.72622741  1.71643653
9       b 2.06170532  4.87756954
10      b 4.68575126 -0.08011508
11      b 0.08401255 -0.04767590
12      b 2.19938816  4.18954758
13      c 3.05634353 -0.89257491
14      c 2.28659319  2.63171152
15      c 4.70525275  1.31450497
16      c 4.02673050 -1.86270620
17      c 5.03640599  2.48564201
18      c 0.95704183  1.27446410</pre>
</li>
<li>the argument of <code>do()</code> can be <strong>named</strong> or <strong>unnamed</strong>:
<ul>
<li>named arguments (more than one supplied) become list-columns, with one element for each group:</li>
</ul>
<pre># Tail (last 3 obs) of x by group
ds %>% group_by(group) %>% do(out=tail(.$x, 3))</pre>
<pre>Source: local data frame [3 x 2]
Groups: &lt;by row>

   group      out
  (fctr)    (chr)
1      a &lt;dbl[3]>
2      b &lt;dbl[3]>
3      c &lt;dbl[3]></pre>
<ul>
<li>unnamed argument (only one supplied) must be a data frame and labels will be duplicated accordingly:</li>
</ul>
<pre># Tail (last 3 obs) of x by group
ds %>% group_by(group) %>% do(data.frame(out=tail(.$x, 3)))</pre>
<pre>Source: local data frame [9 x 2]
Groups: group [3]

   group       out
  (fctr)     (dbl)
1      a 3.8270397
2      a 0.6426337
3      a 0.6519305
4      b 3.3238824
5      b 0.8290942
6      b 4.1538746
7      c 6.5861213
8      c 4.6280643
9      c 0.3599512</pre>
</li>
</ul>
<p>Its use is the same working with customized functions.</p>
<p>Let us define the following function, which performs two simple operations returning a data frame:</p>
<pre>my_fun &lt;- function(x, y){
  res_x = mean(x) + 2
  res_y = mean(y) * 5 
  return(data.frame(res_x, res_y))
}</pre>
<p>If the argument is named the result is:</p>
<pre># Apply my_fun() function to ds by group
ds %>% group_by(group) %>% do(out=my_fun(x=.$x, y=.$y))</pre>
<pre>Source: local data frame [3 x 2]
Groups: &lt;by row>

   group                out
  (fctr)              (chr)
1      a &lt;data.frame [1,2]>
2      b &lt;data.frame [1,2]>
3      c &lt;data.frame [1,2]></pre>
<p>Otherwise, if argument is unnamed the result is:</p>
<pre># Apply my_fun() function to ds by group
ds %>% group_by(group) %>% do(my_fun(x=.$x, y=.$y))</pre>
<pre>Source: local data frame [3 x 3]
Groups: group [3]

   group    res_x     res_y
  (fctr)    (dbl)     (dbl)
1      a 5.005825  9.167546
2      b 5.022282  8.683619
3      c 5.025586 11.240558</pre>
</div>
<div>
<h2>Programming with do_() (Standard Evaluation Version)</h2>
<div>
<div>
<p>How can we enclose the previous operations inside a function? Simple! Using<strong><code>do_()</code></strong> (the SE version of <code>do()</code>) and <strong><code>interp()</code></strong> function of <strong><code>lazyeval</code></strong> package.</p>
<p><code>lazyeval</code> is an R package, written and maintained by Hadley Wickham. It represents a new approach to Non Standard Evaluation (NSE) for R. The difference between SE and NSE approaches is the quoting of input variable names. NSE is suitable for interactive use (see the previous paragraph), but not for programming, for which SE approach is recommended.</p>
<p>Install and load <code>lazyeval</code>, if you haven’t already done it.</p>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce947065840095-1">1</div>
</div>
</td>
<td>
<div>
<div><span>install</span><span>.</span><span>packages</span><span>(</span><span>“lazyeval”</span><span>)</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce94d932077833-1">1</div>
</div>
</td>
<td>
<div>
<div><span>require</span><span>(</span><span>lazyeval</span><span>)</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p><code>interp()</code> helps to build the expression up from a mixture of constants and variables to be passed to <code>.dots</code> argument of <code>dplyr</code> verbs. For more details see <a target="_blank" href="https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html">Non Standard Evaluation vignette</a>.</p>
<p>In the following example <code>interp()</code> is used to build up the expression to be passed to <code>.dots</code> argument of <code>group_by_()</code> (SE version of <code>group_by()</code>), which consists of the grouping variable name. It is used also to build up the expression to be passed to <code>.dots</code> argument of <code>do_()</code>. This expression consists of the function name specifying also its arguments in brackets.</p>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce954311707896-1">1</div>
<div data-line="crayon-57815a80ce954311707896-2">2</div>
<div data-line="crayon-57815a80ce954311707896-3">3</div>
<div data-line="crayon-57815a80ce954311707896-4">4</div>
<div data-line="crayon-57815a80ce954311707896-5">5</div>
<div data-line="crayon-57815a80ce954311707896-6">6</div>
<div data-line="crayon-57815a80ce954311707896-7">7</div>
<div data-line="crayon-57815a80ce954311707896-8">8</div>
<div data-line="crayon-57815a80ce954311707896-9">9</div>
<div data-line="crayon-57815a80ce954311707896-10">10</div>
<div data-line="crayon-57815a80ce954311707896-11">11</div>
</div>
</td>
<td>
<div>
<div><span>fun</span> <span>&lt;</span><span>–</span> <span>function</span><span>(</span><span>data</span><span>,</span> <span>x_var_name</span><span>,</span> <span>y_var_name</span><span>,</span> <span>group_var_name</span><span>)</span><span>{</span></div>
<div><span>  </span><span># group_by_() .dots argument</span></div>
<div><span>  </span><span>group_dots</span> <span>&lt;</span><span>–</span> <span>interp</span><span>(</span><span>~</span> <span>group_var_name</span><span>,</span> <span>group_var_name</span> <span>=</span> <span>as</span><span>.</span><span>name</span><span>(</span><span>group_var_name</span><span>)</span><span>)</span></div>
<div><span>  </span><span># do_() .dots argument</span></div>
<div><span>  </span><span>do_dots</span> <span>=</span> <span>interp</span><span>(</span> <span>~</span> <span>my_fun</span><span>(</span><span>x</span> <span>=</span> <span>.</span><span>[</span><span>[</span><span>x_var_name</span><span>]</span><span>]</span><span>,</span> <span>y</span> <span>=</span> <span>.</span><span>[</span><span>[</span><span>y_var_name</span><span>]</span><span>]</span><span>)</span><span>)</span></div>
<div><span>  </span><span># Operations</span></div>
<div><span>  </span><span>out</span> <span>&lt;</span><span>–</span> <span>data</span> <span>%</span><span>></span><span>%</span></div>
<div><span>    </span><span>group_by_</span><span>(</span><span>.</span><span>dots</span> <span>=</span> <span>group_dots</span><span>)</span> <span>%</span><span>></span><span>%</span></div>
<div><span>    </span><span>do_</span><span>(</span><span>.</span><span>dots</span> <span>=</span> <span>do_dots</span><span>)</span></div>
<div><span>  </span><span>return</span><span>(</span><span>out</span><span>)</span></div>
<div><span>}</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Let us apply the previous function to <code>ds</code> dataset:</p>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce95c659622419-1">1</div>
</div>
</td>
<td>
<div>
<div><span>fun</span><span>(</span><span>data</span><span>=</span><span>ds</span><span>,</span> <span>x_var_name</span><span>=</span><span>“x”</span><span>,</span> <span>y_var_name</span><span>=</span><span>“y”</span><span>,</span> <span>group_var_name</span><span>=</span><span>“group”</span><span>)</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce962588423593-1">1</div>
<div data-line="crayon-57815a80ce962588423593-2">2</div>
<div data-line="crayon-57815a80ce962588423593-3">3</div>
<div data-line="crayon-57815a80ce962588423593-4">4</div>
<div data-line="crayon-57815a80ce962588423593-5">5</div>
<div data-line="crayon-57815a80ce962588423593-6">6</div>
<div data-line="crayon-57815a80ce962588423593-7">7</div>
<div data-line="crayon-57815a80ce962588423593-8">8</div>
</div>
</td>
<td>
<div>
<div><span>Source</span><span>:</span> <span>local </span><span>data </span><span>frame</span> <span>[</span><span>3</span> <span>x</span> <span>3</span><span>]</span></div>
<div><span>Groups</span><span>:</span> <span>group</span> <span>[</span><span>3</span><span>]</span></div>
<div></div>
<div><span>   </span><span>group    </span><span>res_x     </span><span>res_y</span></div>
<div><span>  </span><span>(</span><span>fctr</span><span>)</span><span>    </span><span>(</span><span>dbl</span><span>)</span><span>     </span><span>(</span><span>dbl</span><span>)</span></div>
<div><span>1</span><span>      </span><span>a</span> <span>5.005825</span><span>  </span><span>9.167546</span></div>
<div><span>2</span><span>      </span><span>b</span> <span>5.022282</span><span>  </span><span>8.683619</span></div>
<div><span>3</span><span>      </span><span>c</span> <span>5.025586</span> <span>11.240558</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div>
<h2>Other Examples</h2>
<p><code>do()</code> is often used to fit models and to display the results.<br>
Look at the following functions!</p>
<p>Let us define a function that fits linear model and returns coefficients as a data frame and apply it to <code>ds</code> by <code>group</code>:</p>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce969159807875-1">1</div>
<div data-line="crayon-57815a80ce969159807875-2">2</div>
<div data-line="crayon-57815a80ce969159807875-3">3</div>
<div data-line="crayon-57815a80ce969159807875-4">4</div>
<div data-line="crayon-57815a80ce969159807875-5">5</div>
<div data-line="crayon-57815a80ce969159807875-6">6</div>
</div>
</td>
<td>
<div>
<div><span># Function that fits linear model and returns coefficients as a data frame</span></div>
<div><span>my_fun_2</span> <span>&lt;</span><span>–</span> <span>function</span><span>(</span><span>data</span><span>,</span> <span>x</span><span>,</span> <span>y</span><span>)</span><span>{</span></div>
<div><span>  </span><span>mod</span> <span>=</span> <span>lm</span><span>(</span><span>formula</span> <span>=</span> <span>x</span><span>~</span><span>y</span><span>,</span> <span>data</span> <span>=</span> <span>data</span><span>)</span></div>
<div><span>  </span><span>out</span> <span>=</span> <span>data</span><span>.</span><span>frame</span><span>(</span><span>intercept</span><span>=</span><span>mod</span><span>$</span><span>coefficients</span><span>[</span><span>1</span><span>]</span><span>,</span> <span>slope</span><span>=</span><span>mod</span><span>$</span><span>coefficients</span><span>[</span><span>2</span><span>]</span><span>)</span></div>
<div><span>  </span><span>return</span><span>(</span><span>out</span><span>)</span></div>
<div><span>}</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce970637381738-1">1</div>
<div data-line="crayon-57815a80ce970637381738-2">2</div>
</div>
</td>
<td>
<div>
<div><span># Apply my_fun_2() function (unnamed elements and nse version) to ds by group</span></div>
<div><span>ds</span> <span>%</span><span>></span><span>%</span> <span>group_by</span><span>(</span><span>group</span><span>)</span> <span>%</span><span>></span><span>%</span> <span>do</span><span>(</span><span>my_fun_2</span><span>(</span><span>x</span><span>=</span><span>x</span><span>,</span> <span>y</span><span>=</span><span>y</span><span>,</span> <span>data</span><span>=</span><span>.</span><span>)</span><span>)</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce976820063557-1">1</div>
<div data-line="crayon-57815a80ce976820063557-2">2</div>
<div data-line="crayon-57815a80ce976820063557-3">3</div>
<div data-line="crayon-57815a80ce976820063557-4">4</div>
<div data-line="crayon-57815a80ce976820063557-5">5</div>
<div data-line="crayon-57815a80ce976820063557-6">6</div>
<div data-line="crayon-57815a80ce976820063557-7">7</div>
<div data-line="crayon-57815a80ce976820063557-8">8</div>
</div>
</td>
<td>
<div>
<div><span>Source</span><span>:</span> <span>local </span><span>data </span><span>frame</span> <span>[</span><span>3</span> <span>x</span> <span>3</span><span>]</span></div>
<div><span>Groups</span><span>:</span> <span>group</span> <span>[</span><span>3</span><span>]</span></div>
<div></div>
<div><span>   </span><span>group </span><span>intercept       </span><span>slope</span></div>
<div><span>  </span><span>(</span><span>fctr</span><span>)</span><span>     </span><span>(</span><span>dbl</span><span>)</span><span>       </span><span>(</span><span>dbl</span><span>)</span></div>
<div><span>1</span><span>      </span><span>a</span><span>  </span><span>2.939123</span><span>  </span><span>0.03637955</span></div>
<div><span>2</span><span>      </span><span>b</span><span>  </span><span>3.149110</span> <span>–</span><span>0.07302733</span></div>
<div><span>3</span><span>      </span><span>c</span><span>  </span><span>3.249187</span> <span>–</span><span>0.09946141</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Let us enclose the previous operations inside a function and apply it to <code>ds</code> by<code>group</code>:</p>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce97d153812448-1">1</div>
<div data-line="crayon-57815a80ce97d153812448-2">2</div>
<div data-line="crayon-57815a80ce97d153812448-3">3</div>
<div data-line="crayon-57815a80ce97d153812448-4">4</div>
<div data-line="crayon-57815a80ce97d153812448-5">5</div>
<div data-line="crayon-57815a80ce97d153812448-6">6</div>
<div data-line="crayon-57815a80ce97d153812448-7">7</div>
<div data-line="crayon-57815a80ce97d153812448-8">8</div>
<div data-line="crayon-57815a80ce97d153812448-9">9</div>
<div data-line="crayon-57815a80ce97d153812448-10">10</div>
<div data-line="crayon-57815a80ce97d153812448-11">11</div>
<div data-line="crayon-57815a80ce97d153812448-12">12</div>
<div data-line="crayon-57815a80ce97d153812448-13">13</div>
</div>
</td>
<td>
<div>
<div><span># Enclose the previous operations inside a function</span></div>
<div><span>fun_2</span> <span>&lt;</span><span>–</span> <span>function</span><span>(</span><span>data</span><span>,</span> <span>x_var_name</span><span>,</span> <span>y_var_name</span><span>,</span> <span>group_var_name</span><span>)</span><span>{</span></div>
<div><span>  </span><span># group_by_() .dots argument</span></div>
<div><span>  </span><span>group_dots</span> <span>&lt;</span><span>–</span> <span>interp</span><span>(</span><span>~</span> <span>group_var_name</span><span>,</span> <span>group_var_name</span> <span>=</span> <span>as</span><span>.</span><span>name</span><span>(</span><span>group_var_name</span><span>)</span><span>)</span></div>
<div><span>  </span><span># do_() .dots argument</span></div>
<div><span>  </span><span>do_dots</span> <span>=</span> <span>interp</span><span>(</span> <span>~</span> <span>my_fun_2</span><span>(</span><span>data</span><span>=</span><span>.</span><span>,</span> <span>x</span> <span>=</span> <span>x_var_name</span><span>,</span> <span>y</span> <span>=</span> <span>y_var_name</span><span>)</span><span>,</span></div>
<div><span>                    </span><span>x_var_name</span><span>=</span><span>as</span><span>.</span><span>name</span><span>(</span><span>x_var_name</span><span>)</span><span>,</span> <span>y_var_name</span><span>=</span><span>as</span><span>.</span><span>name</span><span>(</span><span>y_var_name</span><span>)</span><span>)</span></div>
<div><span>  </span><span># Operations</span></div>
<div><span>  </span><span>res</span> <span>&lt;</span><span>–</span> <span>data</span> <span>%</span><span>></span><span>%</span></div>
<div><span>    </span><span>group_by_</span><span>(</span><span>.</span><span>dots</span> <span>=</span> <span>group_dots</span><span>)</span><span>  </span><span>%</span><span>></span><span>%</span></div>
<div><span>    </span><span>do_</span><span>(</span><span>.</span><span>dots</span> <span>=</span> <span>do_dots</span><span>)</span></div>
<div><span>  </span><span>return</span><span>(</span><span>res</span><span>)</span></div>
<div><span>}</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce984469286463-1">1</div>
<div data-line="crayon-57815a80ce984469286463-2">2</div>
</div>
</td>
<td>
<div>
<div><span># Apply fun_2() function (se version) to ds by group</span></div>
<div><span>fun_2</span><span>(</span><span>data</span><span>=</span><span>ds</span><span>,</span> <span>x_var_name</span><span>=</span><span>“x”</span><span>,</span> <span>y_var_name</span><span>=</span><span>“y”</span><span>,</span> <span>group_var_name</span><span>=</span><span>“group”</span><span>)</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div data-settings=" minimize scroll-mouseover wrap">
<div></div>
<div>
<table>
<tbody>
<tr>
<td data-settings="show">
<div>
<div data-line="crayon-57815a80ce98b590612776-1">1</div>
<div data-line="crayon-57815a80ce98b590612776-2">2</div>
<div data-line="crayon-57815a80ce98b590612776-3">3</div>
<div data-line="crayon-57815a80ce98b590612776-4">4</div>
<div data-line="crayon-57815a80ce98b590612776-5">5</div>
<div data-line="crayon-57815a80ce98b590612776-6">6</div>
<div data-line="crayon-57815a80ce98b590612776-7">7</div>
<div data-line="crayon-57815a80ce98b590612776-8">8</div>
</div>
</td>
<td>
<div>
<div><span>Source</span><span>:</span> <span>local </span><span>data </span><span>frame</span> <span>[</span><span>3</span> <span>x</span> <span>3</span><span>]</span></div>
<div><span>Groups</span><span>:</span> <span>group</span> <span>[</span><span>3</span><span>]</span></div>
<div></div>
<div><span>   </span><span>group </span><span>intercept       </span><span>slope</span></div>
<div><span>  </span><span>(</span><span>fctr</span><span>)</span><span>     </span><span>(</span><span>dbl</span><span>)</span><span>       </span><span>(</span><span>dbl</span><span>)</span></div>
<div><span>1</span><span>      </span><span>a</span><span>  </span><span>2.939123</span><span>  </span><span>0.03637955</span></div>
<div><span>2</span><span>      </span><span>b</span><span>  </span><span>3.149110</span> <span>–</span><span>0.07302733</span></div>
<div><span>3</span><span>      </span><span>c</span><span>  </span><span>3.249187</span> <span>–</span><span>0.09946141</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div>
<div>
<div>
<div>
<h3></h3>

</div>
</div>
</div>
</div>
<p> </p>
</div>
</div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/dplyr-do-some-tips-for-using-and-programming/"></div></div><div><a data-url="http://www.r-bloggers.com/dplyr-do-some-tips-for-using-and-programming/" data-counturl="http://www.r-bloggers.com/dplyr-do-some-tips-for-using-and-programming/" data-count="vertical" data-text="dplyr do: Some Tips for Using and Programming" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.milanor.net/blog/dplyr-do-tips-for-using-and-programming/"> MilanoR</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/wnWdOObpZBg"></a></div>