Search code examples
rread.csv

Read csv files in R: last few digits in R randomly change


I am trying to read a csv file in R with a column of large numbers. I followed suggestions of setting options(scipen = 999) to avoid scientific notation. But the last few digits of some numbers have changed compared to the data when I opened it in notepad.

This is the right data when opened in notepad:

10,0.47,,1160592025898684419
11,0.41,,134971995
12,0.27,,1195487952102547461
13,0.77,,175472734
14,0.17,,2933793124
15,0.4,,426903572
16,0.67,,1028041029763706881
17,0.3,,1205324760034562049

And this is the wrong data when I open the csv file by read_csv in R:

enter image description here

As you can see, the numbers in line 10, 12, 16, 17 have changed a bit.

I have checked all the relevant answers of the display of long numbers in R, but none of them explain my problem. Does anyone have any idea why this happens? Thanks!


Solution

  • You might read the column as character, something like:

    df = readr::read_csv(path, col_types = 'c')