Lapply to execute command for a list of variables
<p>I intend to change the order of levels of some factors.
The intention is to apply this command </p>

<pre><code>Df$X1 &lt;- ordered(Df$X1, levels = c("5", "4", "3", "2", "1"))
</code></pre>

<p>to a list of variables (X1 to X2)</p>

<pre><code>        Df &lt;- data.frame(
  X1 = ordered(sample(1:5,30,r=T)),
  X2 = ordered(sample(1:5,30,r=T)),
  X3 = as.factor(sample(1:5,30,r=T)),
  Y = as.factor(sample(1:5,30,r=T))
)

tmplistporadove &lt;- as.list(paste("Df$",names(Df)[1:2],sep=""))
zmena &lt;- lapply(tmplistporadove, function(x) substitute(x &lt;- ordered(x, levels = c("5", "4", "3", "2", "1")))   )
eval(zmena)
</code></pre>

<p>But R just prints this:</p>

<pre><code>X[[i]] &lt;- ordered(X[[i]], levels = c("5", "4", "3", "2", "1"))
</code></pre>