Preserving large numbers

后端 未结 8 1759
一生所求
一生所求 2020-12-01 18:30

I am trying to read a CSV file that has barcodes in the first column, but when R gets it into a data.frame, it converts 1665535004661 to 1.67E+12.<

8条回答
  •  执笔经年
    2020-12-01 19:13

    Since you are not performing arithmetic on this value, character is appropriate. You can use the colClasses argument to set various classes for each column, which is probably better than using all character.

    data.csv:

    a,b,c
    1001002003003004,2,3
    

    Read character, then integers:

    x <- read.csv('test.csv',colClasses=c('character','integer','integer'))
    x
                     a b c
    1 1001002003003004 2 3
    
    
    mode(x$a)
    [1] "character"
    
    mode(x$b)
    [1] "numeric"
    

提交回复
热议问题