Question: Row And Column Names In A Matrix
0
gravatar for deschisandy
5.7 years ago by
deschisandy60
deschisandy60 wrote:

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 • 1.6k views
ADD COMMENTlink modified 5.7 years ago by zx87546.8k • written 5.7 years ago by deschisandy60

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

ADD REPLYlink modified 5.7 years ago • written 5.7 years ago by zx87546.8k

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

ADD REPLYlink written 5.7 years ago by deschisandy60
1
gravatar for zx8754
5.7 years ago by
zx87546.8k
London
zx87546.8k wrote:

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 COMMENTlink written 5.7 years ago by zx87546.8k
Please log in to add an answer.

Help
Access

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