0

I need to convert character class to numeric class in R. My character data shows a very accurate reading and essential for my project. One of the viable solution is using as.numeric to convert it. However, it seems that the coercion stop after several significant figures. Here is an example of the data:

> as.numeric("103.88974726496834")
[1] 103.8897

I thought that this might be printing rounding so I did the double checking:

as.character(as.numeric("103.88974726496834"))=="103.88974726496834" [1] FALSE

So, why did this happen? How to completely coerce the character to numeric?

artidataio
  • 316
  • 4
  • 8
  • It is returning false due to rounding error. You can check this for yourself. – Tim Biegeleisen Jun 07 '16 at 03:22
  • That you see seven digits printed is due to rounding on the print only. Internally the number is not rounded, but it won't be exactly equal to your input. What you have cannot be represented as a `numeric` so you get inequality. – Matthew Lundberg Jun 07 '16 at 03:25

0 Answers0