Timothée HENRY
Timothée HENRY

Reputation: 14614

Use integer64 as a key with data table

I have a column of integer64 and would like to use that as the key, only it does not work as shown below: the value gives NA.

This works

s = data.table(id=1000000107000008595, value=10)
setkey(s, id)
s[J(1000000107000008595)]
#             id value
# 1: 1.00000e+18    10

This does not work

s = data.table(id=as.integer64(1000000107000008595), value=10)
setkey(s, id)
s[J(1000000107000008595)]
#             id value
# 1: 1.00000e+18    NA  # <- NA is the problem

Upvotes: 0

Views: 165

Answers (1)

rbm
rbm

Reputation: 3253

What version of R. packages are you using? I just tried this:

library(bit64)
library(data.table)
s = data.table(id=1000000107000008595, value=10)
setkey(s, id)
s[J(1000000107000008595)]

s = data.table(id=as.integer64(1000000107000008595), value=10)
setkey(s, id)
s[J(1000000107000008595)]

and it gives me

> s = data.table(id=1000000107000008595, value=10)
> setkey(s, id)
> s[J(1000000107000008595)]
      id value
1: 1e+18    10
> 
> s = data.table(id=as.integer64(1000000107000008595), value=10)
> setkey(s, id)
> s[J(1000000107000008595)]
                    id value
1: 1000000107000008576    10

Im on

> version$version.string
[1] "R version 3.2.2 (2015-08-14)"

and sessionInfo() says

other attached packages:
[1] data.table_1.9.6 bit64_0.9-5      bit_1.1-12 

Upvotes: 3

Related Questions