我有一个矩阵,其中包含行名:
mat1.data <- c(1,2,3,4,5,6)
mat1 <- matrix(mat1.data,nrow=3,ncol=2,byrow=TRUE)
rownames(mat1) <- c("a", "b", "c")
colnames(mat1) <- c("t1", "t2")
预期结果
$t1
a b c #I need to preserve rownames
1 3 5
$t2
a b c
2 4 6
我该怎么做?
我有一个矩阵,其中包含行名:
mat1.data <- c(1,2,3,4,5,6)
mat1 <- matrix(mat1.data,nrow=3,ncol=2,byrow=TRUE)
rownames(mat1) <- c("a", "b", "c")
colnames(mat1) <- c("t1", "t2")
预期结果
$t1
a b c #I need to preserve rownames
1 3 5
$t2
a b c
2 4 6
我该怎么做?
使用asplit
和MARGIN = 2
按列拆分:
asplit(mat1, 2)
输出
$t1
a b c
1 3 5
$t2
a b c
2 4 6