title: Convert data type for a list of variables in R
body: <p>I wanted to convert a list of character variables in a data frame to numeric format. I used TRANSFORM and LAPPLY functions.</p>
  
  <p>Method 1</p>
  
  <pre><code>var &lt;- c('year', 'age', 'days', 'visits')
  df &lt;- lapply(var, function(x) {transform(df, x = as.numeric(x))}
  </code></pre>
  
  <p>Method 2</p>
  
  <pre><code>var &lt;- c('year', 'age', 'days', 'visits')
  for (i in 1:length(var)) {
      transform(df, df$var[i] = as.numeric(var[i])
  }
  </code></pre>
  
  <p>But none of them worked.</p>
  
  <p>Could someone tell where the problem is? What is the correct ways to achieve this goal? Thank you!</p>