[datatable-help] Filter rows using integer64 columns

Kevin Ushey kevinushey at gmail.com
Wed Oct 14 21:06:06 CEST 2015


R's syntax doesn't 'know' about 64bit integers, so when you try to write

    a == -688037432807398365

you're really creating a big double and losing some precision in the
resulting comparison.

I think you should construct your 64 bit integers from a string, e.g.

    as.integer64("-688037432807398365")

This will avoid the round-trip to floating point and avoid losses in
precision. By the time the R parser is done with
'-688037432807398365', the number has already lost precision.

Kevin

On Wed, Oct 14, 2015 at 11:46 AM, tjonesd289 <t.jonesd289 at gmail.com> wrote:
> I have loaded data from file. The resulting data.table looks like this:
>> require(data.table)
>>require(bit64)
>> z = fread('mydata.csv')
>> print(z)
>                       a
> 1:  -688037432807398365
> 2:  8910419692287774511
> 3:  7392641969610778497
> 4: -7275864368241016399
> 5:  5280275646239497580
>
>> class(z$a)
> "integer64"
>
> However, I cannot filter z on column a...
>> z[a == -688037432807398365,]
> Empty data.table (0 rows) of 1 cols: a
>
> Similarly,
>> z[a == as.integer64(-688037432807398365),]
> Error in UseMethod("as.data.table") :
>   no applicable method for 'as.data.table' applied to an object of class
> "integer64"
>
> I also noticed that as.integer64 rounds the input (see last 3 digits)....
>> as.integer64(-688037432807398365)
> integer64
> [1] -688037432807398400
>
> Any ideas how to  filter rows using integer64 columns? I suppose I could
> convert to character first, but then what is the point of even having
> integer64?
>
> datatable is version 1.9.4, bit64 is version 0.9-5
>
> Thanks!
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Filter-rows-using-integer64-columns-tp4713594.html
> Sent from the datatable-help mailing list archive at Nabble.com.
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help


More information about the datatable-help mailing list