[R] Creating list from matrix
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Wed Oct 22 13:10:31 CEST 2008
try this:
mat <- matrix(rnorm(12*3), 3)
n <- nrow(mat)
p <- ncol(mat)
ind <- rep(1:4, each = n*p/4)
lapply(split(mat, ind), matrix, nrow = n)
I hope it helps.
Best,
Dimitris
Ron Michael wrote:
> Hello everyone,
> Â
> I have a matrix like :
> Â
> mat <- matrix(rnorm(12*3), 3)
> Â
> Now I want to break that matrix in 4 parts each of them are matrix of (3x3) and put those 4 matrices in a "list" object of length 4
> Â
> Can anyone please tell me how to do that?
>
>
> Get your new Email address!
> Grab the Email name you've always wanted before someone else does!
>
> [[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 guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
More information about the R-help
mailing list