Re: [R] Stacking matrix columns

2023-08-05 Thread Bert Gunter
Or just dim(x) <- NULL. (as matrices in base R are just vectors with a dim attribute stored in column major order) ergo: > x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > x<- 1:20 ## a vector > is.matrix(x) [1] FALSE > dim(x) <- c(5,4) > is.matrix(x) [1] TRUE > attributes(x)

Re: [R] Stacking matrix columns

2023-08-05 Thread avi.e.gross
Steve, As Iris pointed out, some implementations of a matrix are actually of a vector with special qualities. There are sometimes choices whether to store it a row at a time or a column at a time. In R, your data consisted of the integers from 1 to 20 and they clearly are stored a column at a

Re: [R] Stacking matrix columns

2023-08-05 Thread Iris Simmons
You could also do dim(x) <- c(length(x), 1) On Sat, Aug 5, 2023, 20:12 Steven Yen wrote: > 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,]16 11 1

[R] Stacking matrix columns

2023-08-05 Thread Steven Yen
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 > ma