0
votes

So I have two square matrices 4x4 each and I am trying to create a matrix C with the elements as (a11, b11), (a12, b12), (a13, b13),...,(a44, b44), a total of 16 pairs. I am trying to code this in R. I have my initial matrices a_ij and b_ij and I want matrix C from that. Can someone please help me with this?

Here are my matrices:

    mu_ijA <- (matrix(c(seq(4, 16, by=4), seq(10, 22, by=4), seq(16, 28, by=4), seq(22, 34, by=4)), nrow= 4)/100)
    a_ijA <- (4* mu_ijA)
    b_ijA <- (4* (1- mu_ijA))

and I want C=((a11,b11), (a12, b12),...,(a44,b44))

Thanks for the help!

1
cbind(as.numeric(a_ijA), as.numeric(b_ijA))?alistaire
Thanks this works.learning_to_code

1 Answers

1
votes

Matrices can only hold atomic objects, so can't hold co-ordinate pairs. I believe you want an array:

C <- array(c(a_ijA,b_ijA),dim=c(dim(a_ijA),2))
C[1,1,] # notice that comma at the end
[1] 0.16 3.84