Hi, thank you all for the help. The split function works very well.
I have an additional question. If I have a matrix of prices (row = 30, col = 2) in matrix P P: 30 40 31.5 42 .... .... .... 32 43 What is the quickest way to get a new matrix, where each entry is the ln(Pt/Pt-1)? I have no prob doing this using a loop, but that might not be most efficient if my table is huge. Moreover, I've read the apply/lapply functions, but I could not get the right parameters to use. Thank you all for help. K. -----Original Message----- From: Petr Pikal [mailto:[EMAIL PROTECTED] Sent: Thursday, June 15, 2006 10:35 AM To: Wong, Kim Cc: [email protected] Subject: Re: [R] help with table partition Hi maybe ?split and ?t is what you want mat<-matrix(rnorm(1000), 100,10) mat.s<-split(data.frame(mat), rep(1:5, each=20)) #splits mat to list with 5 eqal submatrices lapply(mat.s,t) # transpose matrices in list gives you a list of transposed tables, which is probably better than separate tables. Just change rep(1:5,each=20) to rep (1:170, each=366). or a quicker one without data frame mat <- matrix(rnorm(62220*73), 62220,73) dim(mat) <- c(366,73,170) mat.i <- array(0,dim=c(73,366,170)) for (i in 1:170) mat[ , , i] <- t(mat[ , , i]) HTH Petr On 15 Jun 2006 at 9:38, Wong, Kim wrote: Date sent: Thu, 15 Jun 2006 09:38:29 -0400 From: "Wong, Kim" <[EMAIL PROTECTED]> To: <[email protected]> Subject: [R] help with table partition > Hi, > > > > I have a test_table where the dim is 62220 by 73 (row by col) > > > > I would like to partition the rows into 170 equal parts (170 tables > where each is of dim 366 by 73), and rearrange them horizontally. The > source codes I have: > > > > for (i in 1:170) { > > c = cbind(c,test_table[(367*i+1):(367*(i+1)),2:73]); > > } > > > > Unfortunately, using for loop and cbind for a table of this size > causes long running time. What is the most efficient way to get the > table that I want? > > > > Thanks for any help. > > K. > > > > > ----------------------------------------- > CONFIDENTIALITY NOTICE: This message and any attachments > rel...{{dropped}} > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html Petr Pikal [EMAIL PROTECTED] ----------------------------------------- CONFIDENTIALITY NOTICE: This message and any attachments rel...{{dropped}} ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
