简体   繁体   中英

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:

       [,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

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

matrix(mat)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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