Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to deal with BigINT in R [duplicate]

Tags:

I have a BigInt number.If I try to store it in R

  R> a <- 9223372036854775807
  R> a
   [1] 9.223372e+18

As you can notice its loosing info of last few digits. I tried multiple other ways to solve this but no luck like increasing options(digits = 22) or changing to numeric, double, integer.

 > as.integer(9223372036854775807)
  [1] NA
  Warning message:
  NAs introduced by coercion to integer range 
 R> as.numeric(9223372036854775807)
  [1] 9.223372e+18
 R> as.double(9223372036854775807)
  [1] 9.223372e+18

Can anyone help me with this problem. I want to retain the same original value. I also do not want to install any external package.

like image 313
shivank agrawal Avatar asked Apr 04 '18 04:04

shivank agrawal


1 Answers

We can use as.integer64 from bit64

library(bit64)
as.integer64(as.character(a))
#integer64
#[1] 9223372036854775807
like image 100
akrun Avatar answered Sep 20 '22 12:09

akrun