Row And Column Names In A Matrix
1
0
Entering edit mode
11.4 years ago
deschisandy ▴ 60

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.

r • 2.5k views
ADD COMMENT
0
Entering edit mode

Maybe I am missing something, but is it not better to create this list variable as you populate it?

ADD REPLY
0
Entering edit mode

Oh yes that should be fine. I just would like to know how to do it for one empty matrix template

ADD REPLY
1
Entering edit mode
11.4 years ago
zx8754 12k

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
ADD COMMENT

Login before adding your answer.

Traffic: 2079 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6