Skip to Content

R or MATLAB - Matching column name to modify the corresponding cell in a matrix.

Dear Sir/Madam,

I would like to convert the column with NODE as header in a Matrix below to their corresponding Gene as follows:

   NODE Gene1 Gene2 Gene3 Gene4 Gene5 NODE1 NODE2 NODE3
1 NODE1  0.98  0.98    NA    NA    NA    NA    NA    NA
2 NODE2    NA    NA   0.8   0.8    NA    NA    NA    NA
3 NODE3    NA    NA    NA    NA  0.72  0.72    NA    NA
4 NODE4    NA    NA    NA    NA    NA    NA   0.6   0.6

As

NODE1 = Gene1 and Gene2
NODE2 = Gene3 and Gene4
NODE3 = Gene5 and NODE1 = Gene5 and Gene 1 and Gene2

I would like to move cells in NODE1 NODE2 and NODE3 columns to their corresponding Gene colunms to output a file like this:

   NODE Gene1 Gene2 Gene3 Gene4 Gene5 
1 NODE1  0.98  0.98    NA    NA    NA    
2 NODE2    NA    NA   0.8   0.8    NA    
3 NODE3  0.72  0.72    NA    NA  0.72    
4 NODE4  0.6   0.6     NA   0.6  0.6  

Are there any methods of doing this? Can I use R or MATLAB to do this?

Best regards,

Catherine