在R中串联矩阵 [英] Concatenating Matrices in R
问题描述
如何连接相同列但行数不同的矩阵?例如我
想要连接一个( dim(a) = 15 7000 )
和一个b (dim(b) = 16 7000)
,我希望结果是一个31
行乘7000
列的矩阵.我可以针对不同行和列的矩阵执行此操作吗?假设我要合并一个15行和7000列的矩阵与另一个16行和7500列的矩阵.我可以用它创建一个数据集吗?
How can I concatenate matrices of same columns but different number of rows? For example, I
want to concatenate a ( dim(a) = 15 7000 )
and b (dim(b) = 16 7000)
and I want the result to be a matrix of 31
rows by 7000
columns. Can I do this for matrices of different rows and columns.? Say I want to combine a matrix of 15 rows and 7000 columns with another of 16 rows and 7500 columns. Can I create one dataset with that?
推荐答案
听起来像您在寻找rbind
:
> a<-matrix(nrow=10,ncol=5)
> b<-matrix(nrow=20,ncol=5)
> dim(rbind(a,b))
[1] 30 5
类似地,cbind
水平堆叠矩阵.
Similarly, cbind
stacks the matrices horizontally.
我不确定您最后一个问题的意思(我可以针对不同行和列的矩阵执行此操作吗?")
I am not entirely sure what you mean by the last question ("Can I do this for matrices of different rows and columns.?")
这篇关于在R中串联矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!