Possible bug in 'data.table'

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible bug in 'data.table'

Manta
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?
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in 'data.table'

bbolker
Manta <mantino84 <at> libero.it> writes:

>
> 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
>

[snip]


> 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?
>

  If by "crash" you mean that the program actually terminates (i.e.
not just an error), then this is by definition a bug in data.table --
there is a bug tracker at
https://r-forge.r-project.org/tracker/?group_id=240 , or you
could try contacting the package maintainer (help(package="data.table")
or maintainer("data.table")

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in 'data.table'

Manta
In reply to this post by Manta
As somebody else replied (but for some reason did not get through it) the solution to this is to convert the variable TIME3 from POSIXlt to POSIXct. It works like a charm.

Nevertheless, there is a bug in that R should give me a warning/error message, and not simply crash. I reported the bug to the relevant team.

Thank you,
Marco