Re: [R] Matrix to Vector

2010-06-15 Thread Erik Iverson
George Coyle wrote: Hi All, I am trying to turn a Matrix into a vector for analysis purposes. I need to select only certain columns from the entire matrix for the vector (intraday time intervals). Also I need to transpose the Matrix (so times are in rows) stack each successive new column on

Re: [R] Matrix to Vector

2010-06-15 Thread Sarah Goslee
How about: ?subset ?t ?as.vector I'm not sure transposing is really needed, but without a workable example as requested in the posting guide (hint, hint), it's hard to say for certain. Sarah On Tue, Jun 15, 2010 at 1:51 PM, George Coyle wrote: > Hi All, > > I am trying to turn a Matrix into a v

[R] Matrix to Vector

2010-06-15 Thread George Coyle
Hi All, I am trying to turn a Matrix into a vector for analysis purposes. I need to select only certain columns from the entire matrix for the vector (intraday time intervals). Also I need to transpose the Matrix (so times are in rows) stack each successive new column on top of each other (lates

Re: [R] Matrix to Vector

2010-06-05 Thread steven mosher
: > > > From: steven mosher > > Subject: Re: [R] Matrix to Vector > > To: "Henrique Dallazuanna" > > Cc: r-help@r-project.org > > Received: Saturday, June 5, 2010, 2:44 PM > > as.vector(t(m)) > > [1] 1 9 17 25 33 41 2 10 18 26 34 > > 42

Re: [R] Matrix to Vector

2010-06-05 Thread John Kane
m<-matrix(seq(1,48),nrow=6,byrow=T) as.vector(t(m)) gives me the correct result. Any chance you may have already transformed m ? --- On Sat, 6/5/10, steven mosher wrote: > From: steven mosher > Subject: Re: [R] Matrix to Vector > To: "Henrique Dallazuanna" >

Re: [R] Matrix to Vector

2010-06-05 Thread steven mosher
as.vector(t(m)) [1] 1 9 17 25 33 41 2 10 18 26 34 42 3 11 19 27 35 43 4 12 20 28 36 44 5 13 21 29 37 45 6 14 22 30 38 46 7 15 23 31 39 47 8 16 24 [46] 32 40 48 the result I want is this: [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

[R] Matrix to Vector

2010-06-05 Thread Jorge Ivan Velez
Hi Steven, If I understood correctly, this might do what you want: c(t(m)) HTH, Jorge On Sat, Jun 5, 2010 at 2:12 PM, steven mosher wrote: > Given a matrix of m*n, I want to reorder it as a vector, using a row major > transpose. > > so: > > > m<-matrix(seq(1,48),nrow=6,byrow=T) > > m > [,

Re: [R] Matrix to Vector

2010-06-05 Thread Henrique Dallazuanna
Try this: as.vector(t(m)) On Sat, Jun 5, 2010 at 3:12 PM, steven mosher wrote: > Given a matrix of m*n, I want to reorder it as a vector, using a row major > transpose. > > so: > > > m<-matrix(seq(1,48),nrow=6,byrow=T) > > m > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] > [1,]123

[R] Matrix to Vector

2010-06-05 Thread steven mosher
Given a matrix of m*n, I want to reorder it as a vector, using a row major transpose. so: > m<-matrix(seq(1,48),nrow=6,byrow=T) > m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]12345678 [2,]9 10 11 12 13 14 15 16 [3,] 17 18 19 20 21

Re: [R] matrix to vector

2009-05-29 Thread David Winsemius
Not sure it is really "matrix to vector" but here are a few of attempts: > abM<-matrix(1:9, nrow=3) > rownames(abM) <- letters[1:3] > colnames(abM) <- letters[4:6] > data.frame( cols=colnames(abM)[col(abM)[1:9]], rows= rownames(abM) [row(abM)[1:9]], vals=abM[1:9]) cols rows vals 1da

Re: [R] matrix to vector

2009-05-29 Thread Peter Dalgaard
Ian Coe wrote: Hi, Is there a way to convert a matrix into a vector representing all permutations of values and column/row headings with native R functions? I did this with 2 nested for loops and it took about 25 minutes to run on a ~700x700 matrix. I'm assuming there must be a smarter way

[R] matrix to vector

2009-05-29 Thread Ian Coe
Hi, Is there a way to convert a matrix into a vector representing all permutations of values and column/row headings with native R functions? I did this with 2 nested for loops and it took about 25 minutes to run on a ~700x700 matrix. I'm assuming there must be a smarter way to do this with

[R] matrix to vector

2009-05-29 Thread Ian Coe
Hi, Is there a way to convert a matrix into a vector representing all permutations of values and column/row headings with native R functions? I did this with 2 nested for loops and it took about 25 minutes to run on a ~700x700 matrix. I'm assuming there must be a smarter way to do this with