I have a data set from a text file, 5000 stock’s with 751 data points for 3 years worth of data, it goes from day 1 to 751 then the next stock
N stock date price
1 S1 70516 9.11
2 S1 70517 9.00
.......................
5718864 S5000 100330 64.8
5718865 S5000 100331 64.6
I can load the data using:
data(txt) <- read.table("C:\\test.txt", header=T)
after this however im stuck and i cant find anything on the exchange or google how can i load this into a matrix where there are 751 rows and 5000 coloumns and each point corresponds to just the price
E1 price E5000 price
day1 1 ........ 1
.. ..
.. ..
day751 ........... 1
Take a look at
castfrom the reshape package. You can change your data from a “long” format to a “wide” format and back again. There is also native R functions,reshapefor example, but I feel the reshape or reshape2 package provide an easier interface.