Setorder 使用数据 table,在 posixct 毫秒内不工作

Setorder using data table, not working for posixct milliseconds

我想在一段时间后使用 setorder 对我的数据 table 进行排序。

library(data.table)
DT <- data.table(timestamp=c(as.POSIXct("2013-01-01 17:54:23.577"),
                             as.POSIXct("2013-01-01 17:54:23.568"),
                             as.POSIXct("2013-01-01 17:54:23.909"),
                             as.POSIXct("2013-01-01 17:54:23.901")))
setorder(DT,timestamp)
print(DT)

输出:

                 timestamp
1: 2013-01-01 17:54:23.568
2: 2013-01-01 17:54:23.576
3: 2013-01-01 17:54:23.908
4: 2013-01-01 17:54:23.901

Setorder 无法正确排序数据 table,我不确定原因。是否有可能以某种方式提高灵敏度或任何其他可能的解决方案?

来自帮助文件:

Columns of numeric types (i.e., double) have their last two bytes rounded off while computing order, by defalult, to avoid any unexpected behaviour due to limitations in representing floating point numbers precisely. Have a look at setNumericRounding to learn more.

所以这可能是由于在排序过程中对这些列进行了舍入。您可以使用

将其调整为不舍入
setNumericRounding(0)