Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert number from scientific notation in R

I have a numeric variable imported from Oracle with 17 numbers, for example: 20172334534654667.

Now I imported it from Oracle using dbGetQuery() in R, but R use scientific notation: 2.01723e+16

If I try to convert the number using:

mydata$var <- format(mydata$a, scientific=FALSE)

I obtain 20172334534654600 instead of 20172334534654667 So, the last two numbers are always substituted with 00.

How can I solve it, possibly without using additional packages?

like image 781
user1010441 Avatar asked Oct 26 '25 06:10

user1010441


1 Answers

I was unable to replicate your issue, but I think it would probably be best to use formatC rather than format.

For your case, it could be:

numb <- 20172334534654667
numb

formatC(numb, format = "f", digits = 0)

Which gives:

[1] "20172334534654668"

Hopefully that works for you!

like image 175
Dave Gruenewald Avatar answered Oct 27 '25 20:10

Dave Gruenewald