R数据表二进制搜索未找到行

时间:2014-05-09 12:36:50

标签: r data.table

> str(t2)
Classes ‘data.table’ and 'data.frame':  15349956 obs. of  2 variables:
 $ id      :Class 'integer64'  num [1:15349956] 4.26e-319 4.26e-319 4.26e-319 4.26e-319 4.26e-319 ...
     $ category: int  706 706 706 706 706 706 706 706 706 706 ...
     - attr(*, ".internal.selfref")=<externalptr> 
     - attr(*, "sorted")= chr  "id" "category"

> dput(head(t2))
structure(list(id = structure(c(4.26111856912241e-319, 4.26111856912241e-319, 
4.26111856912241e-319, 4.26111856912241e-319, 4.26111856912241e-319, 
4.26111856912241e-319), class = "integer64"), category = c(706L, 
706L, 706L, 706L, 706L, 706L)), .Names = c("id", "category"), sorted = c("id", 
"category"), class = c("data.table", "data.frame"), row.names = c(NA, 
-6L))


   > head(t2)

      id category
1: 86246      706
2: 86246      706
3: 86246      706

4: 86246      706
5: 86246      706
6: 86246      706

> t2[J(86246,706), nomatch=0]
Empty data.table (0 rows) of 2 cols: id,category

为什么二进制搜索没有找到我们在t2头中看到的行?

1 个答案:

答案 0 :(得分:2)

现在在v1.9.3(可从R-Forge获得)中实现,请参阅NEWS

  

o bit64::integer64现在可用于分组和加入,#5369。感谢James Sams突出UPC和Clayton Stanley        提醒:fread()已经能够检测并阅读integer64一段时间了。

以上OP的例子:

t2[J(as.integer64(86246),706), nomatch=0L]
#       id category
# 1: 86246      706
# 2: 86246      706
# 3: 86246      706
# 4: 86246      706
# 5: 86246      706
# 6: 86246      706