title: Recode multiple column values using mutate_at and creating a new column based on mutated columns in a pipe
body: <p>I have a data frame of questionnaire data in wide format, with each column representing one questionnaire item.</p>
  
  <p>Individually, I know how to recode the values within columns and create new columns based on values found in other columns. However, I am experiencing problems trying to do both in a single pipe.</p>
  
  <p>My data looks like the following:</p>
  
  <pre><code>df &lt;- data.frame(Q1 = c(1, 2, 1, 4), Q2 = c(4, 2, 3, 1), Q3 = c(3, 3, 2, 3),
               Q4 = c(4, 4, 2, 4), Q5 = c(4, 2, 3, 1), Q6 = c(7, 2, 3, 1))
  </code></pre>
  
  <p>Using my sample dataset as an example, I intend to subtract 1 from columns Q1, Q2, and Q3 and replace the original values with the new (subtracted) values. Concurrently, I want to create a new column that contains the mean of Q1, Q2, and Q3 while ignoring any NA values or values that are 3.</p>
  
  <p>I have tried the following code, but the Q1, Q2, and Q3 columns are not updated with the subtracted value.</p>
  
  <pre><code>library(dplyr)
  
  df$mean &lt;- df %&gt;%
    select(Q1, Q2, Q3) %&gt;%
    mutate_all(funs(. - 1)) %&gt;%
    apply(1, function(x) {
      round(mean(x[!is.na(x) &amp; x != 3]), digits = 2)
    })
  </code></pre>
  
  <p>I have tried using <code>mutate_at</code> followed by <code>mutate</code> in a pipe. However, the end result deletes every other column that is not selected. I still want the other columns to be in the final dataset:</p>
  
  <pre><code>df &lt;- df %&gt;%
    select(Q1, Q2, Q3) %&gt;%
    mutate_all(funs(. - 1)) %&gt;%
    mutate(mean = apply(., 1, function(x)
      round(mean(x[!is.na(x) &amp; x != 3]), digits = 2)))
  </code></pre>
  
  <p>Thanks and much appreciated!</p>