title: setting levels inside lapply loop in r
body: <p>I´m trying to clean the factor variables in a dataframe from trailing spaces. However the levels assignment doesnt work inside my lapply function.</p>
  
  <pre><code>rm.space&lt;-function(x){
      a&lt;-gsub(" ","",x)
      return(a)}
  
  
  lapply(names(barn),function(x){
      levels(barn[,x])&lt;-rm.space(levels(barn[,x]))
      })
  </code></pre>
  
  <p>Any ideas how I can assign levels inside a lapply function?</p>
  
  <p>//M</p>