我有一个矩阵A,它是:
A <- matrix(c(1:15), byrow=T, nrow=5)
A
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
[4,] 10 11 12
[5,] 13 14 15
现在我想创建一个矩阵B,其尺寸为8x8(或10x10、15x15等),如下所示:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] 1 2 3 0 0 0 0 0
[2,] 4 5 6 0 0 0 0 0
[3,] 7 8 9 0 0 0 0 0
[4,] 10 11 12 0 0 0 0 0
[5,] 13 14 15 0 0 0 0 0
[6,] 0 0 0 0 0 0 0 0
[7,] 0 0 0 0 0 0 0 0
[8,] 0 0 0 0 0 0 0 0
从A开始,我想要添加列和行到一个8x8的维度中,并且全部替换为零值...有什么想法吗? 非常感谢!