data.table v1.9.2中的POSIXct的舍入毫秒数(1.8.10中的确定) [英] Rounding milliseconds of POSIXct in data.table v1.9.2 (ok in 1.8.10)

查看:132
本文介绍了data.table v1.9.2中的POSIXct的舍入毫秒数(1.8.10中的确定)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的 data.table有一个奇怪的结果 v1.9.2:

I have a weird result for my data.table v1.9.2 :

DT
                 timestamp
1: 2013-01-01 17:51:00.707
2: 2013-01-01 17:51:59.996
3: 2013-01-01 17:52:00.059
4: 2013-01-01 17:54:23.901
5: 2013-01-01 17:54:23.914

str(DT)
Classes ‘data.table’ and 'data.frame':  5 obs. of  1 variable:
 $ timestamp: POSIXct, format: "2013-01-01 17:51:00.707" "2013-01-01 17:51:59.996" "2013-01-01 17:52:00.059" "2013-01-01 17:54:23.901" ...
 - attr(*, "sorted")= chr "timestamp"
 - attr(*, ".internal.selfref")=<externalptr> 

当我应用 duplicateated()函数我得到以下结果:

When I apply the duplicated() function I get the following result:

duplicated(DT)
[1] FALSE FALSE FALSE FALSE  TRUE

得到第5行等于第4行是奇怪的。
这也阻止我加入R中的表格。是否与POSIXct类型有关?

It is weird to get the 5th line equal to the 4th. This also blocks me from joining tables in R. Does is have something to do with POSIXct type?

在skydrive上的DT: DT

DT on skydrive : DT

谢谢。

推荐答案

是的,我用v1.9.2转载了你的结果。

Yes I reproduced your result with v1.9.2.

library(data.table)

DT <- data.table(timestamp=c(as.POSIXct("2013-01-01 17:51:00.707"),
                             as.POSIXct("2013-01-01 17:51:59.996"),
                             as.POSIXct("2013-01-01 17:52:00.059"),
                             as.POSIXct("2013-01-01 17:54:23.901"),
                             as.POSIXct("2013-01-01 17:54:23.914")))

options(digits.secs=3)  # usually placed in .Rprofile

DT
                 timestamp
1: 2013-01-01 17:51:00.707
2: 2013-01-01 17:51:59.996
3: 2013-01-01 17:52:00.059
4: 2013-01-01 17:54:23.901
5: 2013-01-01 17:54:23.914

duplicated(DT)
## [1] FALSE FALSE FALSE FALSE TRUE






从Matt的v1.9.3更新

在v1.9.2中更改了四舍五入,毫秒的POSIXct。更多信息:

There was a change to rounding in v1.9.2 which affected milliseconds of POSIXct. More info here :

将非常小的数字(例如1e-28)分组,在data.table v1.8.10与v1.9.2中分组0.0

Large integers in data.table. Grouping results different in 1.9.2 compared to 1.8.10

因此,v1.9.3中现有的解决方法是:

So, the workaround now available in v1.9.3 is :

> setNumericRounding(1)   # default is 2
> duplicated(DT)
[1] FALSE FALSE FALSE FALSE FALSE

希望你明白为什么当然,你不应该调用 setNumericRounding()

Hope you understand why the change was made and agree that we're going in the right direction.

/ code>,这只是一个解决方法。

Of course, you shouldn't have to call setNumericRounding(), that's just a workaround.

我在跟踪器上提交了一个新项目:

I've filed a new item on the tracker :

#5445数字舍入应为0或1 POSIXct的自动

这篇关于data.table v1.9.2中的POSIXct的舍入毫秒数(1.8.10中的确定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆