Re: [R] Stacking matrix columns

2023-08-06 Thread avi.e.gross
0 NA Inf0 [2,] Inf0 NA Inf0 NA [3,]0 NA Inf0 NA Inf [4,] NA Inf0 NA Inf0 > mat2vec(myNA) [1] NA Inf 0 NA Inf 0 NA Inf 0 NA Inf 0 NA Inf 0 [16] NA Inf 0 NA Inf 0 NA Inf 0 > myvec <- 1:8 > mat2vec(myvec) [1] 1 2 3 4 5 6

Re: [R] Stacking matrix columns

2023-08-06 Thread Ebert,Timothy Aaron
You could use a for loop in a brute force approach. -Original Message- From: R-help On Behalf Of Rui Barradas Sent: Sunday, August 6, 2023 7:37 PM To: Iris Simmons ; Steven Yen Cc: R-help Mailing List Subject: Re: [R] Stacking matrix columns [External Email] Às 01:15 de 06/08/2023

Re: [R] Stacking matrix columns

2023-08-06 Thread Rui Barradas
Às 01:15 de 06/08/2023, Iris Simmons escreveu: 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

Re: [R] Stacking matrix columns

2023-08-06 Thread avi.e.gross
Based on a private communication, it sounds like Steven is asking the question again because he wants a different solution that may be the way this might be done in another language. I think he wants to use loops explicitly and I suspect this may be along the lines of a homework problem for

Re: [R] Stacking matrix columns

2023-08-06 Thread avi.e.gross
Sent: Sunday, August 6, 2023 11:59 AM To: avi.e.gr...@gmail.com Cc: R-help Mailing List Subject: Re: [R] Stacking matrix columns Avi, I was not trying to provide the most economical solution. I was trying to anticipate that people (either the OP or others searching for how to stack columns o

Re: [R] Stacking matrix columns

2023-08-06 Thread Eric Berger
er answer. > > -Original Message- > From: R-help On Behalf Of Eric Berger > Sent: Sunday, August 6, 2023 3:34 AM > To: Bert Gunter > Cc: R-help Mailing List ; Steven Yen > Subject: Re: [R] Stacking matrix columns > > Stacking columns of a matrix is a standard operatio

Re: [R] Stacking matrix columns

2023-08-06 Thread avi.e.gross
, 2023 3:34 AM To: Bert Gunter Cc: R-help Mailing List ; Steven Yen Subject: Re: [R] Stacking matrix columns Stacking columns of a matrix is a standard operation in multilinear algebra, usually written as the operator vec(). I checked to see if there is an R package that deals with multilinear

Re: [R] Stacking matrix columns

2023-08-06 Thread Eric Berger
Stacking columns of a matrix is a standard operation in multilinear algebra, usually written as the operator vec(). I checked to see if there is an R package that deals with multilinear algebra. I found rTensor, which has a function vec(). So, yet another way to accomplish what you want would be:

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 >

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