2016-06-24 13 views
1

Der Versuch, Zeilen zu verwerfen, wo V1 größer als 1 ist OR V3 größer als 0,5Filter data.table Reihen mit zwei numerische Spalten

library(data.table) 
set.seed(45L) 
DT <- data.table(V1=c(1L,2L), 
       V2=LETTERS[1:3], 
       V3=round(rnorm(4),4), 
       V4=1:12) 

# tried this approach to get the rows 
DT[ .(V1<1,V3<0.5) ] 

Error in bmerge(i, x, leftcols, rightcols, io, xo, roll, rollends, nomatch, : 
    x.'V2' is a character column being joined to i.'V2' which is type logical'. 

# found this solution, but it's a very dirty one. Looking for cleaner approach. 
# and being afraid of duplicate rows that meet the two conditions 

rbind(DT[ V1<1 ],DT[ V3<0.5 ]) 
+6

Just do 'DT [V1> 1 | V3> 0.5] 'Hier ist der OR-Teil' | ' – akrun

+0

Ich habe bemerkt, dass du den Beitrag editiert hast. Also wäre es "DT [V1 <1 | V3 <0.5] ' – akrun

+0

so, einfach und so peinlich – useRj

Antwort

-2

Wenn Sie die Zeilen verwerfen, wenn V1 = 1 OR V3 = 0,5 , dann verwenden:

DT = DT[V1>1 & V3<0.5] 

Andernfalls Verwendung:

DT = DT[V1>=1 & V3<=0.5] 
Verwandte Themen