假设我有一个维度为87x2
的矩阵。如何在29x6
r
set.seed(1)
mat1 = matrix(runif(174), 87, 2)
我想在下面这样
> matrix(c(1:12), 6, 2)
[,1] [,2]
[1,] 1 7
[2,] 2 8
[3,] 3 9
[4,] 4 10
[5,] 5 11
[6,] 6 12
> matrix(c(1:12), 2, 6)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 3 5 7 9 11
[2,] 2 4 6 8 10 12
谢谢。
答案 0 :(得分:3)
您可以执行以下操作:
mat1 <- matrix(c(1:12), 6, 2)
matrix(mat1, nrow = 2, ncol = 6)
# [,1] [,2] [,3] [,4] [,5] [,6]
#[1,] 1 3 5 7 9 11
#[2,] 2 4 6 8 10 12
或直接使用dim
dim(mat1) <- c(2, 6)