linear table to matrix format
<p>I would like to convert a linear table to a matrix format. </p>

<p>My input table looks like this and is called "linear_table.tab": </p>

<pre><code> transcript      ortho 
Transcript_1    ORTHO_1
Transcript_2    ORTHO_2
Transcript_3    ORTHO_3
Transcript_4    ORTHO_4
Transcript_5    ORTHO_5
Transcript_6    ORTHO_6
Transcript_7    ORTHO_5
Transcript_8    ORTHO_1
Transcript_9    ORTHO_4
Transcript_10   ORTHO_5
Transcript_11   ORTHO_2
Transcript_12   ORTHO_7
Transcript_13   ORTHO_8
Transcript_14   ORTHO_5
Transcript_15   ORTHO_2
Transcript_16   ORTHO_9
</code></pre>

<p>what I would like my matrix table to look like: </p>

<pre><code>                           Transcript_1 Transcript_2    Transcript_3    Transcript_4    Transcript_5    Transcript_6    Transcript_7    Transcript_8    Transcript_9    Transcript_10   Transcript_11   Transcript_12   Transcript_13   Transcript_14   Transcript_15   Transcript_16
                Transcript_1    0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
                Transcript_2    0   0   0   0   0   0   0   0   0   0   1   0   0   0   1   0
                Transcript_3    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_4    0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
                Transcript_5    0   0   0   0   0   0   1   0   0   1   0   0   0   1   0   0
                Transcript_6    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_7    0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
                Transcript_8    1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_9    0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_10   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
                Transcript_11   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_12   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_13   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_14   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
                Transcript_15   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                Transcript_16   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
</code></pre>

<p>Here is my code using R: </p>

<pre><code>  linear.table &lt;- read.table("linear_table.tab", header=T, sep="\t")
  library(reshape2)
  dcast(linear.table, transcript~ortho, fill=0)
</code></pre>

<p>I get the following output in R: </p>

<pre><code>              transcript ORTHO_1 ORTHO_2 ORTHO_3 ORTHO_4 ORTHO_5 ORTHO_6 ORTHO_7 ORTHO_8 ORTHO_9
        Transcript_1 ORTHO_1       0       0       0       0       0       0       0       0
        Transcript_10       0       0       0       0 ORTHO_5       0       0       0       0
        Transcript_11       0 ORTHO_2       0       0       0       0       0       0       0
        Transcript_12       0       0       0       0       0       0 ORTHO_7       0       0
        Transcript_13       0       0       0       0       0       0       0 ORTHO_8       0
        Transcript_14       0       0       0       0 ORTHO_5       0       0       0       0
        Transcript_15       0 ORTHO_2       0       0       0       0       0       0       0
        Transcript_16       0       0       0       0       0       0       0       0 ORTHO_9
        Transcript_2       0 ORTHO_2       0       0       0       0       0       0       0
        Transcript_3       0       0 ORTHO_3       0       0       0       0       0       0
        Transcript_4       0       0       0 ORTHO_4       0       0       0       0       0
        Transcript_5       0       0       0       0 ORTHO_5       0       0       0       0
        Transcript_6       0       0       0       0       0 ORTHO_6       0       0       0
        Transcript_7       0       0       0       0 ORTHO_5       0       0       0       0
        Transcript_8 ORTHO_1       0       0       0       0       0       0       0       0
        Transcript_9       0       0       0 ORTHO_4       0       0       0       0       0
</code></pre>

<p>I am not sure how to proceed in this aspect using R. </p>