title: Loop through variables to produce balance table
body: <p>I am creating a balance test table using <code>rstatix</code>.
  I can produce the outcome I want for each variable, but cannot get to loop over a number of variables to produce a table to my linking in one go.</p>
  <pre><code>require(dplyr)
  require(rstatix)
  data &lt;- data.frame(group=rep(c(1,2),5), v1=rnorm(10),v2=rnorm(10))
  
  data %&gt;%
    t_test(v1 ~ group,detailed = TRUE) %&gt;%
    adjust_pvalue() %&gt;%
    add_significance(cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
                     symbols = c(&quot;****&quot;, &quot;***&quot;, &quot;**&quot;, &quot;*&quot;, &quot;ns&quot;)) %&gt;%
    select(c(&quot;.y.&quot;,&quot;estimate1&quot;,&quot;estimate2&quot;,&quot;statistic&quot;,&quot;p.adj&quot;,&quot;p.adj.signif&quot;)) %&gt;%
    dplyr::rename(variable = .y.,
                  'training' = estimate1,
                  'test' = estimate2,
                  't-test'=statistic,
                  p=p.adj,
                  sl=p.adj.signif)
  
  </code></pre>
  <p>This fails:</p>
  <pre><code>vars &lt;- c(&quot;V1&quot;, &quot;V2&quot;)
  
  bt &lt;- character(0)
  for(i in 1:length(vars)){
  bt_temp &lt;- data %&gt;%
    t_test(vars[i] ~ group, detailed = TRUE) %&gt;%
    adjust_pvalue() %&gt;%
    add_significance(cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
                     symbols = c(&quot;****&quot;, &quot;***&quot;, &quot;**&quot;, &quot;*&quot;, &quot;ns&quot;)) %&gt;%
    select(c(&quot;.y.&quot;,&quot;estimate1&quot;,&quot;estimate2&quot;,&quot;statistic&quot;,&quot;p.adj&quot;,&quot;p.adj.signif&quot;)) %&gt;%
    dplyr::rename(variable = .y.,
                  'training' = estimate1,
                  'test' = estimate2,
                  't-test'=statistic,
                  p=p.adj,
                  sl=p.adj.signif)
  
  bt &lt;- rbind(bt, bt_temp)
  
  </code></pre>