【发布时间】:2014-10-29 15:58:25
【问题描述】:
我有一个包含非唯一键的数据表:
> dput(sv)
structure(list(kwd = c("a", "a", "b", "b", "c"), pixel = c(1,
2, 1, 2, 2), kpN = c(2L, 2L, 2L, 1L, 1L)), row.names = c(NA,
-5L), class = c("data.table", "data.frame"), .Names = c("kwd",
"pixel", "kpN"), .internal.selfref = <pointer: 0x7fc4aa800778>, sorted = "kwd")
> dput(kwd)
structure(list(kwd = c("a", "b", "c", "z"), kwdN = c(3L, 2L,
1L, 1L)), row.names = c(NA, -4L), class = c("data.table", "data.frame"
), .Names = c("kwd", "kwdN"), .internal.selfref = <pointer: 0x7fc4aa800778>, sorted = "kwd")
为什么会出现这个错误:
> sv[kwd,kwdN:=kwdN]
Starting bmerge ...done in 0 secs
Error in vecseq(f__, len__, if (allow.cartesian || notjoin) NULL else as.integer(max(nrow(x), :
Join results in 6 rows; more than 5 = max(nrow(x),nrow(i)). Check for duplicate key values in i, each of which join to the same group in x over and over again. If that's ok, try including `j` and dropping `by` (by-without-by) so that j runs for each group to avoid the large allocation. If you are sure you wish to proceed, rerun with allow.cartesian=TRUE. Otherwise, please search for this error message in the FAQ, Wiki, Stack Overflow and datatable-help for advice.
Calls: [ -> [.data.table -> vecseq
我期待这样的事情(注意键是:
kwd pixel kpN kwdN
1: a 1 2 3
2: a 2 2 3
3: b 1 2 2
4: b 2 1 2
5: c 2 1 1
此外,我很确定它以前是这样工作的。
这在data.table 1.9.4 中是否发生了变化?
我如何得到我想要的? (kwd[sv] 似乎有效,这是新方法吗?)
【问题讨论】:
-
试试
sv[kwd, kwdN:=i.kwdN] -
allow.cartesian错误不应在此处弹出。这已在 1.9.5 中修复。检查 1.9.5 here 的错误修复下的第 8 点。当i有重复项时,如错误消息所述,您应该使用allow.cartesian=TRUE。 -
不确定你想说什么。我同意这不应该发生,并向您展示了该问题已得到解决的链接。
-
@Arun:我以为你的意思是 1.9.5 已经发布了。我看到情况并非如此,它是一个开发版本。预计何时发布 1.9.6?谢谢。
标签: r data.table