title: Recoding all but one variable in R
body: <p>I'm trying to recode all but one type of element in a column <strong>inside a function</strong>. The column name changes depending on the input of the function, and also the element in the column which shouldn't be recoded changes depending on the function input.</p>
  <p>the data frame (df in code snippet) looks as follows:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>...</th>
  <th>education</th>
  <th>...</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>...</td>
  <td>bachelor</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>master</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>high school</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>high school</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>master</td>
  <td>...</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>but could also look like</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>...</th>
  <th>gender</th>
  <th>...</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>...</td>
  <td>male</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>female</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>female</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>female</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>male</td>
  <td>...</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The output that I want is the following respectively:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>...</th>
  <th>education</th>
  <th>...</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>...</td>
  <td>bachelor</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>rest</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>rest</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>rest</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>rest</td>
  <td>...</td>
  </tr>
  </tbody>
  </table>
  </div><div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>...</th>
  <th>gender</th>
  <th>...</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>...</td>
  <td>male</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>rest</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>rest</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>rest</td>
  <td>...</td>
  </tr>
  <tr>
  <td>...</td>
  <td>male</td>
  <td>...</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I have tried the following:</p>
  <pre><code>select_data &lt;- function(df, col_name, do_not_change){
       df &lt;- df %&gt;%
         dplyr::mutate('{col_name}' = recode(col_name, '{do_not_change}' := {{do_not_change}}, .default = &quot;rest&quot;))
  </code></pre>
  <p>So the calls would look as follows respectively:</p>
  <pre><code># case of education
  education_df &lt;- function(df, education, 'bachelor')
  # case of gender
  gender_df &lt;- function(df, gender, 'male')
  </code></pre>
  <p>However, this doesn't seem to be working. Any help would be greatly appreciated. Thanks a ton in advance!</p>