I have a 2D matrix that I need to add into a 3D matrix, for example:
mx3d <- array(1:60, c(3,4,5))
mx2d <- array(letters[1:15], c(3,5))
Is it possible to add this mx2d into mx3d so that mx3d.new becomes a 3x5x5 matrix? Would it be easier if I convert the matrix as a list? Thanks!
To make it clear, based on what we have in mx2d and mx3d, I want to have something like:
> mx3d.new
, , 1
[,1] [,2] [,3] [,4] [,5]
[1,] 1 4 7 10 "a"
[2,] 2 5 8 11 "b"
[3,] 3 6 9 12 "c"
, , 2
[,1] [,2] [,3] [,4] [,5]
[1,] 13 16 19 22 "d"
[2,] 14 17 20 23 "e"
[3,] 15 18 21 24 "f"
, , 3
[,1] [,2] [,3] [,4] [,5]
[1,] 25 28 31 34 "g"
[2,] 26 29 32 35 "h"
[3,] 27 30 33 36 "i"
, , 4
[,1] [,2] [,3] [,4] [,5]
[1,] 37 40 43 46 "j"
[2,] 38 41 44 47 "k"
[3,] 39 42 45 48 "l"
, , 5
[,1] [,2] [,3] [,4] [,5]
[1,] 49 52 55 58 "m"
[2,] 50 53 56 59 "n"
[3,] 51 54 57 60 "o"
Does that work?
It gives me this: