I am reading a large numeric data from csv. The values have trailing zeroes. When importing the data using read.csv
, additional digits are appended to the end of the number.
Reproducible example:
> options(digits = 22)
> number <- as.character("19.745130761412300000000000000000")
> print(number)
[1] "19.745130761412300000000000000000"
> write.csv(number, "number.csv")
> read.csv("number.csv")
X x
1 1 19.745130761412302
Note the 02 at the end of x.
This behaviour also occurs when using as.numeric
:
> number <- as.character("19.745130761412300000000000000000")
> print(number)
[1] "19.745130761412300000000000000000"
> as.numeric(number)
[1] 19.745130761412302
How can I avoid the extra digits when importing many data? Removing the trailing zeroes prior to read.csv
is not an option. Any help would be greatly appreciated.
Thanks,
Chris