如何将多个[] []与多个键链接在一起

Rag*_*aac 6 r data.table

我想基于一列中的匹配来分配数据data.table, J()并且使用和!J()函数不匹配

library(data.table)
DT <- data.table(x = rep(c("a", "b", "c"), each=2000), y=c(rep(c(1,3,6), each = 1)) , key = c("x", "y"))
Run Code Online (Sandbox Code Playgroud)

我希望J()!J()函数提供与下面代码相同的结果:

DT[J("b")][y !=1] 
Run Code Online (Sandbox Code Playgroud)

我尝试了以下内容,它给出了以下错误:

DT[J("b")][!J(x, 1)]

Error in vecseq(f__, len__, if (allow.cartesian) NULL else as.integer(max(nrow(x),  : 
  Join results in 1920000 rows; more than 4800 = 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.
Run Code Online (Sandbox Code Playgroud)

我尝试了下面的代码,但它没有消除第二个不包含的条件 1

DT[J("b")][!J("1")]
Run Code Online (Sandbox Code Playgroud)

Rag*_*aac 3

这个答案来自阿伦。所有功劳都归于阿伦

library(data.table)
DT <- data.table(x = rep(c("a", "b", "c"), each=2000), y=c(rep(c(1,3,6), each = 1)) , key = c("x", "y"))

DT["b"][!J(unique(x), 1)]
Run Code Online (Sandbox Code Playgroud)

b这基于对包含在column中的所有行的匹配和对column中所有行的x 不匹配来对数据进行子集化。1y