Message-ID: <1357233131.17493.YahooMailNeo@web142605.mail.bf1.yahoo.com>
Date: 2013-01-03T17:12:11Z
From: arun
Subject: splitting matrices
In-Reply-To: <5E1B812FAC2C4A49B3D99593B5A521911C0B52@PRDEXMBX-08.the-lab.llnl.gov>
Hi,
You could also try:
set.seed(51)
mat1<-matrix(sample(1:5000,1116*12,replace=TRUE),nrow=1116)
?dim(mat1)
#[1] 1116?? 12
res1<-lapply(split(as.data.frame(mat1),rep(1:36,each=31)),as.matrix)
?unlist(lapply(res1,nrow))
# 1? 2? 3? 4? 5? 6? 7? 8? 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31
#27 28 29 30 31 32 33 34 35 36
#31 31 31 31 31 31 31 31 31 31
A.K.
----- Original Message -----
From: "MacQueen, Don" <macqueen1 at llnl.gov>
To: eliza botto <eliza_botto at hotmail.com>; "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Thursday, January 3, 2013 11:56 AM
Subject: Re: [R] splitting matrices
This example illustrates a method that may do what you want.
## split a 20x5 matrix into five 4x5 matrices
xmat <- matrix(1:100, nrow=20, ncol=5, byrow=TRUE)
xsplit <- rep( 1:5, times= rep(4,5))
tmp <- split.data.frame(xmat,xsplit)
You will need to change xsplit to fit your dimensions.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 1/3/13 8:40 AM, "eliza botto" <eliza_botto at hotmail.com> wrote:
>
>
>Dear useRs,
>i want to split a matrix having 1116rows and 12 columns. i want to split
>that matrix into 36 small matrices each having 12 columns and 31 rows.
>The big matrix should be splitted row wise. which means that the first
>small matrix should copy values which are in first 31 rows and 12 columns
>of the big matrix. similarly 2nd small matrix should contain values from
>32nd to 63rd row of the big matrix and so on. on the whole i want to have
>36 small matrices.i tried
>dim(dd) <- c(31,12,35)
>but the result are not stisfactory...
>thanks in advance
>elisa ??? ??? ??? ? ??? ??? ?
>??? [[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.
______________________________________________
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.