R: Converting from string to double

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

For example:

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

And the output reads 100. How to I retain the decimals when converting from string to numeric? I've set options(digits=3).

Thanks

Mike

2

1 Answer

The problem is the option you have set:

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 the option to 3 and are shown 3 digits.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like