R: Convert from string to double

I am trying to convert from string to double in R. However, every time I convert a number, R creates an integer.

For example:

a = "100.11"  
a = as.double(a)  

      

And the output is outputting 100

. How to preserve decimal places when converting from string to numeric? I installed options(digits=3)

.

thank

Mike

+3


source to share


1 answer


The problem is that you have installed:

options(digits=3)
as.double("100.11")
#[1] 100
options(digits=5)
as.double("100.11")
#[1] 100.11

      



digits

"controls the number of digits to print when printing numeric values." You set option 3 and 3 digits are displayed.

+6


source







All Articles