Dear all, I have a matrix X which consists of 2 columns. I would like to convert this matrix into a list where every entry of the list consists of a single row of the matrix. Does anyone have a suggestions how to manage this? Thank you for your efforts in advance! Best, Martin [[alternative HTML version deleted]]
Hi> Dear all, > > > > I have a matrix X which consists of 2 columns. I would like to convertthis> matrix into a list where every entry of the list consists of a singlerow of> the matrix.e.g. split(mat, 1:nrow(mat)) Regards Petr> > Does anyone have a suggestions how to manage this? > > > > Thank you for your efforts in advance! > > > > Best, > > > > Martin > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
An embedded message was scrubbed... From: "Filipe Leme Botelho" <filipe.botelho at vpar.com.br> Subject: RES: [R] conversion of matrix into list Date: Wed, 1 Jun 2011 09:17:02 -0300 Size: 2461 URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110601/53fdb8d7/attachment.mht> -------------- next part -------------- "This message and its attachments may contain confidential and/or privileged information. If you are not the addressee, please, advise the sender immediately by replying to the e-mail and delete this message." "Este mensaje y sus anexos pueden contener informaci?n confidencial o privilegiada. Si ha recibido este e-mail por error por favor b?rrelo y env?e un mensaje al remitente." "Esta mensagem e seus anexos podem conter informa??o confidencial ou privilegiada. Caso n?o seja o destinat?rio, solicitamos a imediata notifica??o ao remetente e exclus?o da mensagem."
Martin Spindler wrote:> I have a matrix X which consists of 2 columns. I would like to convert this > matrix into a list where every entry of the list consists of a single row of > the matrix.Here's another way besides split(): # returns a list of the matrix m's rows (rowcol=1) or columns mat2lst <- function(m,rowcol=1) { if (rowcol == 1) m <- t(m) dm <- as.data.frame(m) as.list(dm) } This seems to be faster than the split() approach for columns, but slower for rows. Apparently the transpose operation makes the difference. (You could try investigating via Rprof().) Norm Matloff