[R] Stacking matrix columns

Steven Yen @tyen @end|ng |rom ntu@edu@tw
Sun Aug 6 02:11:28 CEST 2023


I wish to stack columns of a matrix into one column. The following 
matrix command does it. Any other ways? Thanks.

 > x<-matrix(1:20,5,4)
 > x
      [,1] [,2] [,3] [,4]
[1,]    1    6   11   16
[2,]    2    7   12   17
[3,]    3    8   13   18
[4,]    4    9   14   19
[5,]    5   10   15   20

 > matrix(x,ncol=1)
       [,1]
  [1,]    1
  [2,]    2
  [3,]    3
  [4,]    4
  [5,]    5
  [6,]    6
  [7,]    7
  [8,]    8
  [9,]    9
[10,]   10
[11,]   11
[12,]   12
[13,]   13
[14,]   14
[15,]   15
[16,]   16
[17,]   17
[18,]   18
[19,]   19
[20,]   20
 >



More information about the R-help mailing list