我想根据一列中的匹配对数据进行子集化,而使用 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"))
我正在寻找
J()
和 !J()
函数提供与以下代码相同的结果:DT[J("b")][y !=1]
我尝试了以下操作,但出现以下错误:
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.
我尝试了下面的代码,但它没有消除不包含
1
的第二个条件。DT[J("b")][!J("1")]
最佳答案
这个答案来自阿伦。所有的功劳都归功于阿伦
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)]
这根据包含
b
的所有行的匹配来对数据进行子集化。在栏目x
与 1
不匹配在列 y
的所有行中.
关于r - 如何使用多个键将多个 [ ] [ ] 链接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23450376/