An Elegant way to change columns type in dataframe in R
<p>I have a data.frame which contains columns of different types, such as integer, character, numeric, and factor.</p>

<p>I need to convert the integer columns to numeric for use in the next step of analysis. </p>

<p><strong>Example</strong>: <code>test.data</code> includes 4 columns (though there are thousands in my real data set): <code>age</code>, <code>gender</code>, <code>work.years</code>, and <code>name</code>; <code>age</code> and <code>work.years</code> are integer, <code>gender</code> is factor, and <code>name</code> is character. What I need to do is change <code>age</code> and <code>work.years</code> into a numeric type. And I wrote one piece of code to do this.</p>

<pre><code>test.data[sapply(test.data, is.integer)] &lt;-lapply(test.data[sapply(test.data, is.integer)], as.numeric)
</code></pre>

<p>It looks not good enough though it works. So I am wondering if there is some more elegant methods to fulfill this function. Any creative method will be appreciated.</p>