-2

can anyone explain me why this works like it works... It seems to be a problem with big numbers I think. Is there a way to fix it without casting the id column to character?

library(data.table)
data <- data.table(id = c(11111111111111, 11111111111112))
data[id == 11111111111111]
data[as.numeric(id) == 11111111111111]
data[, .N, by = id]
data[, .N, by = as.numeric(id)]
data[, .N, by = as.character(id)]

Thank you for any help!

Daniel
  • 5
  • 1

2 Answers2

0

Set options(scipen=20) before running the code. This should give you the result you want

Documentation for scipen:

scipen: integer. A penalty to be applied when deciding to print numeric values in fixed or exponential notation. Positive values bias towards fixed and negative towards scientific notation: fixed notation will be preferred unless it is more than scipen digits wider.

krish
  • 1,388
  • 2
  • 18
  • 28
0

As akrun mentions in a comment

I am using R 3.3.2 and data.table 1.10.0.

I've updated the data.table package to the version 1.10.0 and it works fine.

Community
  • 1
  • 1
Daniel
  • 5
  • 1