如何创建重复的矩阵并将其合并到R中?
要创建重复的矩阵,我们可以使用复制函数,该函数将重复原始矩阵,如果我们想将这些矩阵合并在一起,则可以将rbind与do.call一起使用。例如,如果我们有一个名为M的矩阵,则可以创建一个副本并将其合并在一起,可以使用以下命令-
do.call(rbind,replicate(2,M,simplify=FALSE))
示例
M<-matrix(rpois(25,5),ncol=5)输出结果M
[,1] [,2] [,3] [,4] [,5][1,] 3 5 6 8 7
[2,] 3 8 6 4 6
[3,] 8 5 5 4 7
[4,] 7 6 5 7 4
[5,] 3 3 4 4 3
do.call(rbind,replicate(2,M,simplify = FALSE))
[,1] [,2] [,3] [,4] [,5][1,] 3 5 6 8 7
[2,] 3 8 6 4 6
[3,] 8 5 5 4 7
[4,] 7 6 5 7 4
[5,] 3 3 4 4 3
[6,] 3 5 6 8 7
[7,] 3 8 6 4 6
[8,] 8 5 5 4 7
[9,] 7 6 5 7 4
[10,] 3 3 4 4 3
do.call(rbind,replicate(3,M,simplify = FALSE))
[,1] [,2] [,3] [,4] [,5][1,] 3 5 6 8 7
[2,] 3 8 6 4 6
[3,] 8 5 5 4 7
[4,] 7 6 5 7 4
[5,] 3 3 4 4 3
[6,] 3 5 6 8 7
[7,] 3 8 6 4 6
[8,] 8 5 5 4 7
[9,] 7 6 5 7 4
[10,] 3 3 4 4 3
[11,] 3 5 6 8 7
[12,] 3 8 6 4 6
[13,] 8 5 5 4 7
[14,] 7 6 5 7 4
[15,] 3 3 4 4 3
do.call(rbind,replicate(4,M,simplify = FALSE))
[,1] [,2] [,3] [,4] [,5][1,] 3 5 6 8 7
[2,] 3 8 6 4 6
[3,] 8 5 5 4 7
[4,] 7 6 5 7 4
[5,] 3 3 4 4 3
[6,] 3 5 6 8 7
[7,] 3 8 6 4 6
[8,] 8 5 5 4 7
[9,] 7 6 5 7 4
[10,] 3 3 4 4 3
[11,] 3 5 6 8 7
[12,] 3 8 6 4 6
[13,] 8 5 5 4 7
[14,] 7 6 5 7 4
[15,] 3 3 4 4 3
[16,] 3 5 6 8 7
[17,] 3 8 6 4 6
[18,] 8 5 5 4 7
[19,] 7 6 5 7 4
[20,] 3 3 4 4 3
do.call(rbind,replicate(6,M,simplify = FALSE))
[,1] [,2] [,3] [,4] [,5][1,] 3 5 6 8 7
[2,] 3 8 6 4 6
[3,] 8 5 5 4 7
[4,] 7 6 5 7 4
[5,] 3 3 4 4 3
[6,] 3 5 6 8 7
[7,] 3 8 6 4 6
[8,] 8 5 5 4 7
[9,] 7 6 5 7 4
[10,] 3 3 4 4 3
[11,] 3 5 6 8 7
[12,] 3 8 6 4 6
[13,] 8 5 5 4 7
[14,] 7 6 5 7 4
[15,] 3 3 4 4 3
[16,] 3 5 6 8 7
[17,] 3 8 6 4 6
[18,] 8 5 5 4 7
[19,] 7 6 5 7 4
[20,] 3 3 4 4 3
[21,] 3 5 6 8 7
[22,] 3 8 6 4 6
[23,] 8 5 5 4 7
[24,] 7 6 5 7 4
[25,] 3 3 4 4 3
[26,] 3 5 6 8 7
[27,] 3 8 6 4 6
[28,] 8 5 5 4 7
[29,] 7 6 5 7 4
[30,] 3 3 4 4 3
以上是 如何创建重复的矩阵并将其合并到R中? 的全部内容, 来源链接: utcz.com/z/342600.html