A matrix is a vector with a dim() attribute. Values are stored in column major order (first column on top of second column on top of ...). Thus, if mymatrix is your matrix,
mymatrix[as.logical(mymatrix)] gives c(2,4,3), because as.logical(0) = FALSE, as.logical(nonzero) = TRUE. If you are really doing serious work with sparse matrices , you should look at the sparseM package. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Mike Jones > Sent: Wednesday, November 09, 2005 8:14 AM > To: [email protected] > Subject: [R] elements in a matrix to a vector > > 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]] > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
