Using index to reference column in summarise() in dplyr - R
<p>I would like to reference a column inside the summarise() in dplyr with its index rather than with its name. For example:</p>

<pre><code>        &gt; a

           id visit timepoint bedroom  den
            1   0     0        62      NA 
            2   1     0        53    6.00  
            3   2     0        56    2.75   
            4   0     1        55      NA 
            5   1     2        61      NA 
            6   2     0        54      NA 
            7   0     1        58    2.75   
            8   1     2        59      NA 
            9   2     2        60      NA 
            10  0     1        57      NA 

           # E.g. 
           a %&gt;% group_by(visit) %&gt;% summarise(avg.bedroom = mean(bedroom, na.rm   =T)
           # Returns
        visit avg.dedroom
        &lt;dbl&gt;       &lt;dbl&gt;
     1     0       4.375
     2     1       2.750
     3     2         NaN
</code></pre>

<p>How could I use the index of column "bedroom" rather its name in the summarise clause?   I tried:</p>

<pre><code>     a %&gt;% group_by(visit) %&gt;% summarise("4" = mean(.[[4]], na.rm = T))
</code></pre>

<p>but this returned false results:</p>

<pre><code>       visit      `4`
        &lt;dbl&gt;    &lt;dbl&gt;
      1     0 3.833333
      2     1 3.833333
      3     2 3.833333
</code></pre>

<p>Is my objective achievable and if yes how?  Thank you.</p>