r - data.table 1.8.11 和聚合问题

标签 r data.table

关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

7年前关闭。




Improve this question




更新 : 错误已修复。见下文。

这是我在 data.table 1.8.11 (r1101, 2014-01-28) 中发现的一些有趣行为。 by 子句中包含的变量的顺序会更改聚合的结果:

>   foo = data.table(a=rep(c(0,1,0,1),2), b=rep(c(T,T,F,F),2), c=c(1,1,1,1,1,1,1,1))
>   foo
   a     b c
1: 0  TRUE 1
2: 1  TRUE 1
3: 0 FALSE 1
4: 1 FALSE 1
5: 0  TRUE 1
6: 1  TRUE 1
7: 0 FALSE 1
8: 1 FALSE 1
>   foo[, .N, by=list(b, a)]
       b a N
1:  TRUE 0 1
2:  TRUE 1 1
3: FALSE 0 1
4: FALSE 1 1
5:  TRUE 0 1
6:  TRUE 1 1
7: FALSE 0 1
8: FALSE 1 1
>   foo[, .N, by=list(a, b)]
   a     b N
1: 0  TRUE 2
2: 1  TRUE 2
3: 0 FALSE 2
4: 1 FALSE 2
> 

这不会发生在 data.table (1.8.10) 的稳定版本中。

最佳答案

谢谢举报。这现已在 v1.8.11 提交 1103 中得到修复。来自 NEWS :

o Fixed a bug that arose due to recent fixes to fastorder, where aggregating with logical type at times lead to to wrong result. This closes #5307. Thanks to Clayton Stanley for reporting on SO: data.table 1.8.11 and aggregation issues


require(data.table) # commit 1103 v1.8.11
foo[, .N, by=list(b,a)]
       b a N
1:  TRUE 0 2
2:  TRUE 1 2
3: FALSE 0 2
4: FALSE 1 2

foo[, .N, by=list(a,b)]
   a     b N
1: 0  TRUE 2
2: 1  TRUE 2
3: 0 FALSE 2
4: 1 FALSE 2

关于r - data.table 1.8.11 和聚合问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21437546/

相关文章:

r - ggplot2 - 引用汇总统计/层

r - 将多个 csv 文件平均为 r 中的 1 个平均文件

r - 如何根据时间戳列制作时间跨度列?

r - 做什么 。 (点)和 %(百分比)在 R 中是什么意思?

通过从另一个变量中获取值来随机替换值

r - 在 R 中使用 lavaan 包的交互模型

r - R 的趋势向上和向下函数

R - 如何在交替列表元素的同时绑定(bind)两个列表

r - 计算 R data.table 中前 3 行的总和(通过 grid-square)

R 数据聚合与组上的 WHERE 子句