Hi. Can anyone help me? I want to create a vector from specific matrix-elements( e.g.[1,1]) these matrices are elements of a list. Is there any possibility to work without a loop? (e.g. with "lapply"?) hope, you can help me thank you Michael [[alternative HTML version deleted]]
"Michael Kirschbaum" <emkiba at gmx.de> writes:> I want to create a vector from specific matrix-elements( e.g.[1,1]) > these matrices are elements of a list.> Is there any possibility to work without a loop? (e.g. with "lapply"?)Sounds like you want lapply(mlist, "[", i = 1, j = 1) where mlist is your list of matrices.
Have you considere "unlist"? Also, note that a matrix is a vector with a dim attribute, and a data.frame is actually a list with some other attributes. hope this helps. spencer graves Michael Kirschbaum wrote:> Hi. > Can anyone help me? > I want to create a vector from specific matrix-elements( e.g.[1,1]) these matrices are elements of a list. > Is there any possibility to work without a loop? (e.g. with "lapply"?) > hope, you can help me > thank you > Michael > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Michael Kirschbaum wrote:> Hi. > Can anyone help me? > I want to create a vector from specific matrix-elements( e.g.[1,1]) these matrices are elements of a list. > Is there any possibility to work without a loop? (e.g. with "lapply"?) > hope, you can help me > thank you > Michael > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-helpsapply(list, function(x) x[1,1]) Uwe Ligges
Something like this? myvec <- sapply(list.of.mat, function(x) x[i, j]) If all the matrices are of the same dimension, it might be easier to make them into an array, and just "slice" through the array. Andy> -----Original Message----- > From: Michael Kirschbaum [mailto:emkiba at gmx.de] > Sent: Wednesday, July 16, 2003 10:24 AM > To: r-help at stat.math.ethz.ch > Subject: [R] turning list-elements into a vector > > > Hi. > Can anyone help me? > I want to create a vector from specific matrix-elements( > e.g.[1,1]) these matrices are elements of a list. Is there > any possibility to work without a loop? (e.g. with "lapply"?) > hope, you can help me thank you Michael > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, ...{{dropped}}
hi Emkiba, try this: x <- matrix(1:12, 4, 3) y <- matrix(x, 12, 1) yy <- y[,1] regards, Huan Internet emkiba at gmx.de@stat.math.ethz.ch - 07/16/2003 03:24 PM Sent by: r-help-bounces at stat.math.ethz.ch To: r-help cc: Subject: [R] turning list-elements into a vector Hi. Can anyone help me? I want to create a vector from specific matrix-elements( e.g.[1,1]) these matrices are elements of a list. Is there any possibility to work without a loop? (e.g. with "lapply"?) hope, you can help me thank you Michael [[alternative HTML version deleted]] ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help This message and any attachments (the "message") is\ intende...{{dropped}}