title: How do I summarize means across columns, including a calculated column?
body: <p>How would I use the <code>dplyr</code> <code>summarize</code> function in order to calculate the mean across all columns, but include the results from a custom column that requires the raw data?  </p>
  
  <p>Here's an example using the <code>msleep</code> dataset.  I want the result to be one line showing the means, and the correct result for the <code>sleep_tot_rem</code> column that I created.  </p>
  
  <pre><code>library(tidyverse)
  
  # Incorrect calculation for Mutated Column
  msleep %&gt;% filter(!is.na(sleep_rem)) %&gt;% mutate(sleep_tot_rem = sleep_total / sleep_rem) %&gt;% 
    summarize_if(is.numeric, mean, na.rm=TRUE)
  #&gt; # A tibble: 1 x 7
  #&gt;   sleep_total sleep_rem sleep_cycle awake brainwt bodywt sleep_tot_rem
  #&gt;         &lt;dbl&gt;     &lt;dbl&gt;       &lt;dbl&gt; &lt;dbl&gt;   &lt;dbl&gt;  &lt;dbl&gt;         &lt;dbl&gt;
  #&gt; 1        10.4      1.88       0.440  13.6   0.106   63.3          6.97
  
  # Correct calculation for mutated column
  msleep %&gt;% filter(!is.na(sleep_rem)) %&gt;% summarize_if(is.numeric, sum, na.rm=TRUE) %&gt;% 
    mutate(sleep_tot_rem = sleep_total / sleep_rem)
  #&gt; # A tibble: 1 x 7
  #&gt;   sleep_total sleep_rem sleep_cycle awake brainwt bodywt sleep_tot_rem
  #&gt;         &lt;dbl&gt;     &lt;dbl&gt;       &lt;dbl&gt; &lt;dbl&gt;   &lt;dbl&gt;  &lt;dbl&gt;         &lt;dbl&gt;
  #&gt; 1        634.      114.        14.1  830.    5.11  3861.          5.54
  </code></pre>
  
  <p>Thanks in advance.  </p>