0

Hello I am trying to convert number to integer in R but when a number is too large it is converted to NA, why? How can I avoid this problem?

just some example

>df[,2] 
[1]          0          0          0          0          0          0          0    5361230  780600500          0          0          0
 [13]  764111150          0          0          0          0         9999816350 0         23237410347   91198500 1957077150  124890245   64232150

>as.integer(df[,2])
 [1]          0          0          0          0          0          0          0    5361230  780600500          0          0          0
 [13]  764111150          0          0          0          0         NA          0         NA   91198500 1957077150  124890245   64232150

I would like to mantain the NA as the original number is it possible? thanks

jogo
  • 12,469
  • 11
  • 37
  • 42
Dr.PhilCol
  • 21
  • 5

1 Answers1

4

Your number is too large to fit into an integer:

23237410347 > .Machine$integer.max
## [1] TRUE

Maybe it is good enough to use double. Also, there is a package that supports 64 bit integers (R natively supports 32 bit).

library(bit64)

as.integer64(23237410347)
## integer64
## [1] 23237410347
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341