[R] reorganizing a data frame
Jeff Miller
jdm at xnet.com
Sat Jul 8 00:17:56 CEST 2000
Hi,
I have what I think is an easy question.
I have a data frame, called stockdata, of stock prices that looks like this:
date ticker close
1 01/02/1998 GE 24.667
2 01/05/1998 GE 25.104
3 01/06/1998 GE 24.771
4 01/07/1998 GE 24.979
5 01/08/1998 GE 24.750
6 01/02/1998 HIT 71.125
7 01/05/1998 HIT 72.313
8 01/06/1998 HIT 72.563
9 01/02/1998 INTC 36.313
10 01/05/1998 INTC 37.250
11 01/06/1998 INTC 36.563
12 01/07/1998 INTC 36.375
13 01/08/1998 INTC 37.156
I would like to turn this data frame into a matrix, closedata, that looks like
this
GE HIT INTC
01/02/1998 24.667 71.125 36.313
01/05/1998 25.104 72.313 37.250
01/06/1998 24.771 72.563 36.563
01/07/1998 24.979 NA 36.375
01/08/1998 24.750 NA 37.156
What is the best way to do this?
I can see how to do it using a loop, but that is a problem when
I have lots of stocks on lots of dates.
Thanks much,
Jeff Miller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000707/cbd92722/attachment.html
More information about the R-help
mailing list