Hello I have the following dataframe returned using the RBloomberg library:
> tt <- bdh(conn, secs, \"last price\", \"20110501\")
> tt
tic
What comes to my mind is the use of tapply:
tapply(tt$price, list(date=tt$date, ticker=tt$ticker), mean)
As Mean for one element is the element itself, this should be the same. You only may get in trouble once you have more than one value for one day and ticker. (But, then, your requirement is not well defined)
Have a look at the dcast
function in package reshape2
:
library(reshape2)
dcast(tt, date ~ ticker)
date EURUSD USDBRL USDINR USDTRY USDZAR
1 2011-05-01 NA NA NA NA NA
2 2011-05-02 1.4830 1.5893 44.3350 1.5218 6.6090
3 2011-05-03 1.4825 1.5876 44.5150 1.5336 6.6394
4 2011-05-04 1.4827 1.6182 44.4675 1.5471 6.6837
5 2011-05-05 1.4539 1.6220 44.7625 1.5488 6.7250
6 2011-05-06 1.4316 1.6149 44.7950 1.5445 6.7051
7 2011-05-07 NA NA NA NA NA
8 2011-05-08 NA NA NA NA NA