title: How to recode a set of variables in a dataframe in R
body: <p>I have a dataframe with different variables containing values from 1 to 5. I want to recode some variables in the way that 5 becomes 1 and vice versa (x=6-x). 
  I want to define a list of variables, that will be recoded like this in my dataframe.</p>
  
  <p>Here is my approach using <code>lapply</code>. I haven't really understood it yet. </p>
  
  <pre><code>  #generate example-dataset
      var1&lt;-sample(1:5,100,rep=TRUE)
      var2&lt;-sample(1:5,100,rep=TRUE)
      var3&lt;-sample(1:5,100,rep=TRUE)
      dat&lt;-as.data.frame(cbind(var1,var2,var3))
  
      recode.list&lt;-c("var1","var3")  
      recode.function&lt;- function(x){          
      x=6-x
       }
      lapply(recode.list,recode.function,data=dat)
  </code></pre>