Skip to content

How to split a matrix into a few matrices?

2 messages · ayu2008, Henrique Dallazuanna

#
Hi dear users,

I try to split a matrix into a few matrices, for example, suppose that I
have 1000X4 matrix from mvrnorm(1000,m,c) with 

m<-matrix(c(0,0,0,2),4,1)   and 
c<-matrix(c(1.0,0.2,-0.5,0.3,0.2,1,0.2,-0.5,-0.5,0.2,1,0.2,0.3,-0.5,0.2,1),4,4,byrow=T)


How to split the matrix into

a. 2 matrices which the first one consists of the first 500 rows, and the
second one consist of the last 500 rows

b. split the matrix equally and sequentially (according to the order of the
rows) into say 10 matrices with 100 x 4 dimension

c. how to do (b) randomly, not following the order of the rows, but without
any overlapping. So all the 10 matrices will consists of different values
from the original matrix.

Your help is very much appreciated....thank you


ayu
#
Try this:

a <- mvrnorm(100, m, c)
On Wed, Jan 27, 2010 at 9:50 AM, ayu2008 <ayuazwal at yahoo.com> wrote:
split(as.data.frame(a), rep(1:2, each = 500))
split(as.data.frame(a), rep(1:100, each = 10))
split(as.data.frame(a)[sample(1:nrow(a)),], rep(1:10, each = 10))