~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我的做法是先写了个函数,输入是一个给定的矩阵和每一行要重复的次数,输出则是想要的矩阵。
repMat <- function(x, each = NULL) {
if (is.null(each)) return(x)
n <- nrow(x)
if (length(each) != n) stop("Number of rows in x should be equal to the length of each!")
res <- NULL
for (i in 1:n) {
currentline <- matrix(rep(x[i, ], each), nrow = each, byrow = TRUE)
res <- rbind(res, currentline)
}
return(res)
}