[R] help with table partition
davidr at rhotrading.com
davidr at rhotrading.com
Thu Jun 15 20:06:48 CEST 2006
apply(log(P), 2, diff)
David L. Reiner
Rho Trading Securities, LLC
Chicago IL 60605
312-362-4963
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Wong, Kim
Sent: Thursday, June 15, 2006 11:30 AM
To: Petr Pikal; Jacques VESLOT
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] help with table partition
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:petr.pikal at precheza.cz]
Sent: Thursday, June 15, 2006 10:35 AM
To: Wong, Kim
Cc: r-help at stat.math.ethz.ch
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" <kwong at nymex.com>
To: <r-help at stat.math.ethz.ch>
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}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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
petr.pikal at precheza.cz
-----------------------------------------
CONFIDENTIALITY NOTICE: This message and any attachments\ re...{{dropped}}
More information about the R-help
mailing list