R: numerics coerced into characters while reading data in transposed form, so how to easily convert things back?
<p>Say I have a data file in transposed form (i.e. rows are variables, columns are observations), like this:</p>

<pre><code>name    A    B    C  
gender  M    F    M  
age     25   26   27
</code></pre>

<p>I read the file into R: <code>dat &lt;- read.table(datafile, row.names=1, as.is=TRUE)</code>. Since data.frame needs values of homogeneous type in each column, the "age" row is coerced into characters.</p>

<p>Then I would transpose <code>dat</code> back to "normal" form: <code>dat_t &lt;- t(dat)</code>. Now "age" is a column but the values are still characters.</p>

<p>Now my source data is large with many rows that should be numeric interspersed among many character rows. So after the transposition how can I easily convert the types of all the columns to what they should be?</p>

<p>Thank you. This is my first question so I'm not very good at searching for previous answers or asking proper questions. I apologize in advance if the question is trivial or duplicated.</p>