Row And Column Names In A Matrix
I have the matrix in the following form:
A-B A-C A-D A-E B-C B-D B-E C-D C-E D-E
GENE 1
GENE 2
GENE 3
GENE 4
and would like to create an empty matrix template of the following form as a list:
[[GENE 1]]
A B C D E
A
B
C
D
E
[[GENE 2]]
A B C D E
A
B
C
D
E
[[GENE 3]]
A B C D E
A
B
C
D
E
[[GENE 4]]
A B C D E
A
B
C
D
E
This is for a large dataset and hence has to be automated. The number of rows and columns in the original matrix is much higher than this. This is only a subset of the data.
• 2,851 views
•
link
1 answer
Try this:
x <- array(0, dim=c(2,3,4))
x
#output
, , 1
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
, , 2
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
, , 3
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
, , 4
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
• 161 views
•
link
Log in to answer this question.
Maybe I am missing something, but is it not better to create this list variable as you populate it?
Oh yes that should be fine. I just would like to know how to do it for one empty matrix template