2014-05-03 22 views
6

anahtarbirden fazla I <code>data.table</code>, <code>J()</code> ve <code>!J()</code> fonksiyonları kullanılarak bir sütunda bir uyum ve başka herhangi bir eşleşme göre verileri alt kümesi istiyoruz

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")) 

Ben J() ve !J() işlevleri aşağıda kodu olarak aynı sonucu vermesini sağlamaktır arıyorum:

DT[J("b")][y !=1] 

denedim aşağıdaki ve aşağıdaki hata verdi:
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. 
Ben aşağıdaki kodu denedim ama Bu cevap Arun geldi 1

DT[J("b")][!J("1")] 
+1

Teşekkür ederim Arun, sorunu çözdü –

cevap

3

dahil etmek değil, ikinci koşulu ortadan kaldırmamıştır. Tüm kredi Bu sütunda x yılında b içeren tüm satırlar için bir maç ve sütunun y tüm satırlarda 1 hiçbir maç dayalı veri alt gruplarını

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)] 

Arun gider.

İlgili konular