Question: how to convert R contingency table to a matrix that will be used to merge with other matrix
0
gravatar for M K
4.9 years ago by
M K510
United States
M K510 wrote:

Dear All,

I created a contingency table between gene names and repeats count in each gene as shown below:

"(CA)n" "(TG)n" "AT_rich" "B1_Mm" "B1_Mur1" "B1_Mur2" 

"0610005C13Rik" 0 0 1 0 0 0 
"0610007N19Rik" 0 0 0 0 0 0  
"0610007P14Rik" 0 0 1 0 1 0  
"0610008F07Rik" 0 0 0 0 0 0  
"0610009B14Rik" 0 1 0 0 1 0 

Now I need to merge this file with another file (data frame) using the gene name as a reference in both files.In the other file  which is as data frame I have the gene name in the first column but in the file above which is a  contingency table, I couldn't use the gene name because it doesn't appear as a separate column. so how can I convert this contingency table to normal count table with gene names in the first column and repeats counts in the other columns.

R • 3.1k views
ADD COMMENTlink modified 4.9 years ago by mkulecka320 • written 4.9 years ago by M K510
0
gravatar for mkulecka
4.9 years ago by
mkulecka320
European Union
mkulecka320 wrote:

I came up with a bit convoluted solution:

class(your_table)<-"matrix"
df<-as.data.frame(your_table)
df$gene_name<-rownames(df)
merged_df<-merge(df,your_other_data_frame,by="gene_name")
ADD COMMENTlink modified 10 months ago by RamRS30k • written 4.9 years ago by mkulecka320

Thanks for helping me, but there is one problem which is in the R code above the gene name will treated as a character while in my other file it is treated as a factor, so is there any way to convert it to be a factor.

ADD REPLYlink written 4.9 years ago by M K510
df$gene_name<-as.factor(df$gene_name)
ADD REPLYlink modified 10 months ago by RamRS30k • written 4.9 years ago by mkulecka320
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1036 users visited in the last hour