0
$\begingroup$

I have two matrices; I want to convert the row names of first matrix to gene symbol from matched ensemble=gene symbol from second matrix

> head(mat1[,1:2])
                TCGA-L5-A4OG-11A-12R-A260-31
ENSG00000000003                         1818
ENSG00000000005                            0
ENSG00000000419                         1436
ENSG00000000457                         1175
ENSG00000000460                          242
ENSG00000000938                          536
                TCGA-IC-A6RE-11A-12R-A336-31
ENSG00000000003                         4596
ENSG00000000005                            3
ENSG00000000419                          751
ENSG00000000457                          840
ENSG00000000460                          205
ENSG00000000938                          253
> 

> dim(mat1)
[1] 56925    11
> 

> head(mat2)
                ensembl              symbol
ENSG00000274572 ENSG00000274572       ZYXP1
ENSG00000159840 ENSG00000159840         ZYX
ENSG00000162378 ENSG00000162378      ZYG11B
ENSG00000232242 ENSG00000232242    ZYG11AP1
ENSG00000203995 ENSG00000203995      ZYG11A
ENSG00000070476 ENSG00000070476        ZXDC
> 

> dim(mat2)
[1] 36848     2
> 

How I can do that in R?

Thank you

$\endgroup$
1
  • 2
    $\begingroup$ I'm voting to close this question as off-topic because it is not about bioinformatics $\endgroup$
    – llrs
    Mar 20, 2019 at 16:54

1 Answer 1

4
$\begingroup$

Since they share the ensembl_ID column, you can merge them, then assign the symbol column to the rownames, then delete the symbol column.

something like:

merged <- merge(mat1, mat2, by = 0) 
rownames(merge) <- merged[,'symbol'] 
merged[,symbol] <- NULL

https://stat.ethz.ch/R-manual/R-devel/library/base/html/merge.html

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.