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]]
Try this: lapply(split(as.data.frame(t(mat)), rep(1:(ncol(mat)/3), each = 3)), t) On Wed, Oct 22, 2008 at 8:56 AM, Ron Michael <ron_michael70@yahoo.com>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@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. > >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
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