[R] list element to matrix

jim holtman jholtman at gmail.com
Wed Sep 5 23:48:37 CEST 2007


If they are already a matrix in the list, then you don't have to use
'as.matrix'; you can just say:

M1 <- D[[1]]

Now the question is, what do you mean by how do you index M1?  Do you
want to go through the list applying a function to each matrix?  If
so, then just 'lapply'.  For example, to get the column means, you
would do:

mean.list <- lapply(D, colMeans)

Can you explain in a little more detail the problem you are trying to solve.

On 9/5/07, dverzi at mail.sdsu.edu <dverzi at mail.sdsu.edu> wrote:
> I have created a list of "matrices" using sapply or lapply and wish to extract each of the "matrices" as a matrix.  Some of them are 2x2, 3x3, etc.
>
> I can do this one at a time as:
>
> M1<-as.matrix(D[[1]])
>
> How can repeat this process for an unknown number of entries in the list?  In other words, how shall I index M1?
>
> Diana
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list