[R] Possible bug in 'data.table'

Manta mantino84 at libero.it
Tue May 14 12:32:04 CEST 2013


Dear R users,

I may have found a bug in the function 'data.table'. I have a similar
question as the one in this post:

http://stackoverflow.com/questions/3367190/aggregate-and-weighted-mean-in-r

I have a dataset with assets, quantity traded, date and time. I would like
to calculate the value weighted average time of trades, by date of trade.
The variables are as follows:

Classes ‘data.table’ and 'data.frame':	307787 obs. of  12 variables:
$ CODE    : int 1 2 3 4 4 5 3 2 2 1
 $ DATE     : int  20070102 20070102 20070102 20070102 20070102 20070102
20070102 20070102 20070102 20070102 ...
 $ TIME     : chr  "09:14:14" "09:14:33" "09:26:19" "09:40:45" ...
 $ PRICE    : num  105.2 105.2 96.8 96.9 96.8 ...
 $ QTY      : int  5000000 5000000 5000000 10000000 5000000 5000000 10000000
3000000 10000000 5000000 ...
 $ DATE2    : Date, format: "2007-01-02" "2007-01-02" "2007-01-02"
"2007-01-02" ...
 $ TIME2    : chr  "09:14:14" "09:14:33" "09:26:19" "09:40:45" ...
 $ TIME3    : POSIXlt, format: "2013-05-13 09:14:14" "2013-05-13 09:14:33"
"2013-05-13 09:26:19" "2013-05-13 09:40:45" ...
 - attr(*, ".internal.selfref")=<externalptr> 

If I run the command 

temp[,list(weighted.mean(PRICE,QTY)),by=DATE2] 

I get

           DATE2        V1
   1: 2007-01-02 100.67024
   2: 2007-01-03  99.89599
   3: 2007-01-04 100.54347
   4: 2007-01-05 100.82472
   5: 2007-01-08  99.39865
  ---                     
1524: 2012-12-19 103.73392
1525: 2012-12-20 103.77344
1526: 2012-12-21 102.89063
1527: 2012-12-27 101.53089
1528: 2012-12-28 103.35999

While I run the command 

temp[,list(weighted.mean(TIME3,QTY)),by=DATE2]

R crashes. This behavior occurs in both R Studio and R GUI, regardless of
the version (2.14, 2.15, 3.0). Is it really a bug or am I doing something
wrong?



--
View this message in context: http://r.789695.n4.nabble.com/Possible-bug-in-data-table-tp4667025.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list