Question: How to replace rownames in one data frame with column in another data frame
0
5 weeks ago
anamaria • 40

Hi,

I have a dataframe which looks like this:

>head(candidate_gene_exprs1)
             DwC_1026_30mM.1 DwC_1026_30mM.2 DwC_1026_30mM.3 DwC_1026_norm.1 DwC_1026_norm.2 DwC_1026_norm.3 DwC_6009_30mM.1
ILMN_1762337        4.803651        4.531582        4.992943        5.077257        4.363542        4.520649        4.221391
ILMN_3241953        5.877695        6.127418        6.094072        5.815746        6.155299        5.859430        5.890158
ILMN_1735045        7.133542        7.251070        7.260408        7.253772        7.256665        7.169209        7.270749
ILMN_2375184        5.650717        5.889364        5.942529        5.768990        5.895180        5.833825        3.953553
ILMN_1659452        5.910706        6.170079        6.218347        5.975649        6.133477        6.132866        4.250749
ILMN_1755321        5.458909        5.232720        5.311850        5.759837        5.320741        5.112800        5.585782

And I would like to replace thesse ILMN rownames there with corresponding values in column GeneSymbol in this dataframe:

> head(mypro)
                           illumina_probe_id      geneSymbol
ILMN_1762337      ILMN_1762337      MACC1
ILMN_3241953      ILMN_3241953      GGACT
ILMN_1735045      ILMN_1735045     A4GALT
ILMN_2375184      ILMN_2375184  NPSR1-AS1
ILMN_1659452      ILMN_1659452  NPSR1-AS1
ILMN_1755321      ILMN_1755321       AAAS

I tried doing this:

ismr3 <- lapply(candidate_gene_exprs1, function(x){ row.names(x)<-as.character(mypro$geneSymbol)})

but I got:

 Error in `rownames<-`(x, value) : 
  attempt to set 'rownames' on an object with no dimensions

One of the obvious issues here is that some entries in mypro$geneSymbol are not unique and that is not allowed in rownames. My ultimate goal is to create a matrix where there geneSymbol names would be columns in matrix and DwC_# names would be rows in that matrix.

R • 50 views
ADD COMMENTlink 5 weeks ago anamaria • 40 • updated 5 weeks ago swbarnes2 5.7k
0
5 weeks ago
swbarnes2 5.7k
United States

Have you looked up the "merge" function? I think that's the safest way to make sure that everyone ends up where it should Once the database are merged, you can make any column the rownames, and delete what you don't want.

ADD COMMENTlink 5 weeks ago swbarnes2 5.7k
0

sure I will do the merge function and that will give me Gene column in my original data frame. But then how to transform that merged data frame into matrix where columns would be entries on that Gene column and rows these DwC_#?

ADD REPLYlink 5 weeks ago
anamaria
• 40
0

Have you looked up how to transpose a data table?

ADD REPLYlink 5 weeks ago
swbarnes2
5.7k

Login before adding your answer.

Powered by the version 1.4