How to change the name of the rows and column in second matrix

array3<-array(c(vector1,vector2,vector3,
vector4),dim=c(3,3,2),
dimnames=list(c("r1","r2","r3"),
c("cl1","cl2",
"cl3"),c("matrix1","matraix2")
))
this the array i have created ,
, , matrix1

cl1 cl2 cl3
r1 5 10 13
r2 9 11 14
r3 3 12 15

, , matraix2

cl1 cl2 cl3
r1 9 6 3
r2 1 0 14
r3 0 11 1

and this is result ,
Hear in matrix 2 , instead of row names r1,r2,r3 , i wanted to have r4,r5,r6 similarly for columns to
cl4,cl5,cl6

can anyone help me out with this

Hi, I'm reasonably certain that each entry of dimnames must be of length no greater than the corresponding entry of dim. With that in mind, can you do what you need to do with a list of matrices?

# 3x3x2 array
array(
  1:18,
  dim = c(3, 3, 2),
  dimnames = list(
    c("r1", "r2", "r3"),
    c("c1", "c2", "c3"),
    c("matrix1", "matrix2")
  )
)

# list of 3x3 matrices
list(
  matrix1 = matrix(1:9, nrow = 3, dimnames = list(c("r1", "r2", "r3"), c("c1", "c2", "c3"))),
  matrix2 = matrix(10:18, nrow = 3, dimnames = list(c("r4", "r5", "r6"), c("c4", "c5", "c6")))
)

I just used the vector 1:18 as data because I don't know what vector1, vector2, vector3, and vector4 were in your code (I can infer it from the output, but that's a bit hard for me to do).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.