R数据表二分查找未找到行

标签 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 head 中看到的行?

最佳答案

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

o bit64::integer64 now works in grouping and joins, #5369. Thanks to James Sams for highlighting UPCs and Clayton Stanley.
Reminder: fread() has been able to detect and read integer64 for a while.

关于上面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

关于R数据表二分查找未找到行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23564849/

相关文章:

r - 如何让我的线条更合身、更整洁?

r - 轻松检查目标是否记录在其他变量中?

r - 根据嵌套列表融化data.table

r - 在函数中按名称传递 data.table 列

r - N 在 R 中选择 K 函数不起作用——我错过了什么?

r - 矩阵下标和线性索引之间的转换(如 matlab 中的 ind2sub/sub2ind)

r - R 中的列表(或字典)列表

r - data.table 在合并中分配 `sapply`

R:计算一组子集的均值

r - 如何使用rbind合并具有POSIXct和Date列类的数据表?