简体   繁体   English

R:扩展矩阵的第一列

[英]R: Extending first column of matrix

I generated this matrix with mat=matrix(c(1,2,3,4,5,6), nrow = 2, ncol = 2) and I got this result: 我用mat=matrix(c(1,2,3,4,5,6), nrow = 2, ncol = 2)生成了这个矩阵,得到了以下结果:

       [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

How can I add the second and third column to the first, like this: 如何将第二列和第三列添加到第一列,如下所示:

         [,1] 
    [1,]    1   
    [2,]    2    
    [3,]    3    
    [4,]    4
    [5,]    5 
    [6,]    6

Is there any specific function that can solve this even If I would have 10 columns and I want them all added to the first column 即使我有10列并且我希望将它们全部添加到第一列中,是否有任何特定功能可以解决此问题?

我们可以只使用matrix包装,它返回一个单列对象

matrix(mat)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM