Question: (Closed) Extracting row and column names from matrix in R.
gravatar for kandoigaurav
5.6 years ago by
United States
kandoigaurav150 wrote:

I've two large matrices with p-values and correlation coefficients for lncRNA vs mRNA genes (both matrix have same structure, one has p-values while the other has corresponding correlation coefficients). I would like to extract all lncRNA-mRNA gene pairs for which the p-value is less than 0.05 and their corresponding correlation coefficients as well.


I'm using the following R script which gives me the row and column number, but I also want the names, i.e lncRNA and mRNA gene names:

Pmatrix = read.csv ("pmatrix.csv", header = FALSE) ##read the matrix with pvalues
sig_values <- which(Pmatrix<0.05, ##extract values less than 0.05
sig_values #list all (row,col) pairs with pvalues less than 0.05
Corr_Matrix = read.csv("corr_matrix.csv", header = FALSE) ##read the matrix with correlation values
Corr_Matrix[sig_values] ##list correlation values corresponding to pvalues less than 0.05.


This gives me a list of row and column numbers, but how can I get the names?

matrix correlation R • 12k views
ADD COMMENTlink modified 5.6 years ago • written 5.6 years ago by kandoigaurav150

This is not really a bioinformatics question, it can be reduced to the generic R question: Extracting row and column names from matrix in R. (as you wrote yourself). Therefore it might be closed. Please read: ?rownames ?colnames. However you won't have any sensible col names, yours will be V1, V2, ... because of header=FALSE, and you won't have row.names either, because they were not defined during import, see ?read.csv and argument row.names.

In addition, the returned value of read.table is a data.frame not a matrix, as your variable names imply.

If you read you should be prepared for these basic tasks.


ADD REPLYlink modified 5.6 years ago • written 5.6 years ago by Michael Dondrup48k

Hello kandoigaurav!

We believe that this post does not fit the main topic of this site.

Decided to close because it is a generic R question.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink written 5.6 years ago by Michael Dondrup48k
Please log in to add an answer.
The thread is closed. No new answers may be added.


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