Skip to content

rounding issue in fwrite  #3862

@haohua

Description

@haohua

Hi guys,

when i am writing some numerical data out to text file with data.table::fwrite, it lost precision, which is by design because of the 16 decimal point limit.

But, here is a confusing part I have for fwrite, two set of data, one with 0.xxxx, and the other with 5.xxxx.
The output file gives different ranking order, compared with the original data.

library(data.table)
testNum1 = c(0.87804878048780566,
             0.87804878048780477,
             0.87804878048780477)
fwrite(x = data.table(value = testNum1), 'test1.txt')
testNumRead1 = fread('test1.txt')

testNum2 = c(5.87804878048780566,
             5.87804878048780477,
             5.87804878048780477)
fwrite(x = data.table(value = testNum2), 'test2.txt')
testNumRead2 = fread('test2.txt')


frank(testNum1)
# [1] 3.0 1.5 1.5
frank(testNumRead1)
[1] 3.0 1.5 1.5

frank(testNum2)
# [1] 3.0 1.5 1.5
frank(testNumRead2)
[1] 2 2 2

can anyone help me to understand the issue here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions