title: Change type of columns according to a vector in R
body: <p>I'm dealing with changing formats in R.</p>
  <p>I have 2 dataframes:</p>
  <ul>
  <li>The main one <code>df</code></li>
  <li>Another dataframe <code>tmp</code> which describes columns types of <code>df</code> and the <strong>New_format</strong> on which columns should be converted</li>
  </ul>
  <p>Here is a reproducible example:</p>
  <pre><code>df &lt;- data.frame(var1 = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;),
                   var2 = c(1,2,3), 
                   var3 = c(&quot;d&quot;, &quot;e&quot;, &quot;f&quot;))
  
  tmp &lt;- data.frame(Variable = c(&quot;var1&quot;, &quot;var2&quot;, &quot;var3&quot;), 
                    Format = c(&quot;character&quot;, &quot;numeric&quot;, &quot;character&quot;),
                    New_format = c(&quot;character&quot;, &quot;integer&quot;, &quot;factor&quot;))
  </code></pre>
  <p>I'd like to convert types of columns where <strong>New_format</strong> is different from <strong>Format</strong>. I've struggled a lot by using lapply function but did not manage to do it.</p>
  <p>It would be really nice if you have any idea :)</p>
  <p>Thanks a lot!</p>