1

This is the weirdest error, it seems that read.csv/read.table changes the value of a number when it's too big

read.table(text="a,b
1123363730,5000000000000011111",sep=",",header=TRUE)
#            a                   b
# 1 1123363730 5000000000000011264

the value of b changed!

read.table(text="a,b
1123363730,5000000000000011111",sep=",")
#           V1                  V2
# 1          a                   b
# 2 1123363730 5000000000000011111

Now the value is correct (as a string)

I suppose it has to do with the number being to big, but it's very annoying, how can I make sure I load what's in my csv ?

moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
  • Probably a duplicate of [this](https://stackoverflow.com/q/32339636/324364). – joran Jun 26 '17 at 17:29
  • Perhaps use [bit64](https://cran.r-project.org/web/packages/bit64/bit64.pdf) and specify `colCasses` in `read.table` as `integer64`? – Dan Jun 26 '17 at 17:32
  • the answer was actually as simple as this (not in proposed link for duplicate) : `read.table(text="5000000000000011111",numerals="no.loss")` – moodymudskipper Aug 03 '17 at 08:43

2 Answers2

1

You're trying to import an integer that is too large-- it will be rounded and expressed in scientific notation.

You can see the effect of going above the maximum integer by 1:

> str(.Machine$integer.max)
 int 2147483647
> str(.Machine$integer.max + 1)
 num 2.15e+09

I believe that maximum integer is unique to each unique machine and R configuration (please someone correct me if I am wrong).

Phantom Photon
  • 768
  • 2
  • 10
  • 20
0
library(bit64)

tst <- read.table(text="a,b
                  1123363730,5000000000000011111",sep=",",
                  header=TRUE, colClasses = "integer64")

print(tst$b)
Dan
  • 11,370
  • 4
  • 43
  • 68
  • I added a single extra zero to this and it failed and gave a default value of 9223372036854775807. This same value is given for all additional zeroes added. This is the largest 64 bit number. – akaDrHouse Jun 26 '17 at 17:40