title: Recoding factor levels and labels (multiple variables at once) in R
body: <p>I have a dataframe with factors coded with 1 = yes and 2 = no. The factors are all named ending on <code>_L</code>. Note that in the real dataframe, they are not all next to each other.</p>
  
  <pre><code>df &lt;- data.frame(var_L = factor(c(1,1,1,2,2,2), labels = c("yes","no")),
                   var2_L = factor(c(1,2,1,2,1,2), labels = c("yes","no")),
                   var3_L = factor(c(1,1,2,2,1,2), labels = c("yes","no")))
  </code></pre>
  
  <p>I want to change level/label 1 = yes to 0 = truth and 2 = no to 1 = lie. I want ro recode them by their name, and there are more than 100 variables.</p>
  
  <p>I'm searching for a solution since three days, but I can't find a command to change levels and labels at once and to do it for multiple variables.</p>