Re: [R] elements in a matrix to a vector

2005-11-09 Thread Ray Brownrigg
> my apologies to everyone taking the time to answer this question. i > didn't explain myself very well. > > i have the indices of the elements of the matrix and the matrix won't > necessarily have zeros everywhere else. is there a way to use the > indices to strip the elements i need? > RTFM

Re: [R] elements in a matrix to a vector

2005-11-09 Thread Mike Jones
again...mj -Original Message- From: Dave Roberts [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 09, 2005 12:28 PM To: Mike Jones Cc: r-help@stat.math.ethz.ch Subject: Re: [R] elements in a matrix to a vector Mike, It's not clear whaty way you are doing it now, but t

Re: [R] elements in a matrix to a vector

2005-11-09 Thread Dave Roberts
Mike, It's not clear whaty way you are doing it now, but this works > x <- matrix(c(0,2,0,0,0,4,3,0,0),nrow=3) > x [,1] [,2] [,3] [1,]003 [2,]200 [3,]040 > y <- as.vector(t(x)) > z <- y[y!=0] > z [1] 3 2 4 Dave Mike Jones wrote: > hi all, >

Re: [R] elements in a matrix to a vector

2005-11-09 Thread Berton Gunter
ginal Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Mike Jones > Sent: Wednesday, November 09, 2005 8:14 AM > To: r-help@stat.math.ethz.ch > Subject: [R] elements in a matrix to a vector > > hi all, > > i'm trying to get elements in a m

Re: [R] elements in a matrix to a vector

2005-11-09 Thread roger koenker
If you are really looking for a way to extract the non-zero elements you can use something like the following: > library(SparseM) > A [,1] [,2] [,3] [1,]003 [2,]200 [3,]040 > as.matrix.csr(A)@ra [1] 3 2 4 there is a tolerance parameter in the coercion

Re: [R] elements in a matrix to a vector

2005-11-09 Thread Peter Dalgaard
"Mike Jones" <[EMAIL PROTECTED]> writes: > hi all, > > i'm trying to get elements in a matrix into a vector. i need a > "streamlined" way to do it as the way i'm doing it is not very > serviceable. an example is a 3x3 matrix like > > 0 0 3 > 2 0 0 > 0 4 0 > > to a vector like > > 3 2 4 You

[R] elements in a matrix to a vector

2005-11-09 Thread Mike Jones
hi all, i'm trying to get elements in a matrix into a vector. i need a "streamlined" way to do it as the way i'm doing it is not very serviceable. an example is a 3x3 matrix like 0 0 3 2 0 0 0 4 0 to a vector like 3 2 4 thanks...mj [[alternative HTML version deleted]] _