[R-SIG-Finance] Question about re-order the dataframe

Gabor Grothendieck ggrothendieck at gmail.com
Tue Apr 10 21:04:18 CEST 2007


Use merge.  You can omit the varying= argument and the line before
the merge statement if you are not too fussy about the column names.

DF <- head(DF, 19) # last ticker now only has 4 closes
DATE.names <- unique(as.character(DF$DATE))
reshape(DF, direction = "wide", idvar = "TICKER", timevar = "DATE",
   varying = list(DATE.names))


On 4/10/07, Brian Wu <bwu at guzman.com> wrote:
> Hi,
> I have a data.frame as following,
>
>           DATE TICKER    CLOSE
> 1  2000-06-30      A 73.75000
> 2  2000-07-07      A 67.43750
> 3  2000-07-14      A 76.87500
> 4  2000-07-21      A 47.50000
> 5  2000-07-28      A 41.31250
> 6  2000-06-30     BB 24.98000
> 7  2000-07-07     BB 23.60500
> 8  2000-07-14     BB 28.91750
> 9  2000-07-21     BB 27.73000
> 10 2000-07-28     BB 26.16750
> 11 2000-06-30           CC 11.86500
> 12 2000-07-07           CC 11.67750
> 13 2000-07-14           CC 11.55250
> 14 2000-07-21           CC 11.49000
> 15 2000-07-28           CC 11.61500
> 16 2000-06-30           DD 4.15625
> 17 2000-07-07     DD 4.62500
> 18 2000-07-14     DD  4.68750
> 19 2000-07-21           DD 4.56250
> 20 2000-07-28     DD 4.18750
>
> I wanna generate a matrix based on this data.frame has the TICKER as row nams and DATE as column names.
> The matrix should be look like this:
>
>        2000-06-30      2000-07-07      2000-07-14      2000-07-21      2000-07-28
> A       73.75000         67.43750        76.87500       47.50000         41.31250
> BB      .....
> CC      .....
> DD      .....
>
> Is there any easy way to do that?
> One problem is there maybe TICKER doesn't have 5 CLOSEs.
>
> Thanks for any suggestion!!!
>
> Brian
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list