2

I am trying to load a database

There is a column which contains quite long strings which correspond to code numbers (for instance 078000000000000000)

When I load the data, R turns these numbers into double (so 7,8 E+15)

If I try to turn it into a character with as.character, it simply becomes "7,8 E+15" so I still lose information

By the way, when loading the data I'm using :

my_data <- fread(file)

And the data is correct, although there is this type problem

Roland
  • 127,288
  • 10
  • 191
  • 288
MBB
  • 347
  • 3
  • 18
  • 7
    I think you can use the colClasses argument in fread, see [here](https://stackoverflow.com/questions/18699816/using-colclasses-in-fread) – Florian Jul 26 '17 at 11:29
  • If you don't want to drop the leading 0, [see this post](https://stackoverflow.com/questions/18699816/using-colclasses-in-fread) on using `colClasses` in `fread`. – lmo Jul 26 '17 at 11:48
  • Thanks it worked perfectly ! – MBB Jul 26 '17 at 12:25

1 Answers1

2

See the documentation. data.table can read in 64bit integers if you install the bit64 package.

install.packages("bit64")
fread("078000000000000000
      ")
#                  V1
#1: 78000000000000000

Or for importing as characters:

fread("078000000000000000
      ", colClasses = "character")
#                   V1  
#1: 078000000000000000
Roland
  • 127,288
  • 10
  • 191
  • 288