R Not in a subset

Possible duplicate:
The standard way to remove multiple items from a data framework

I know in R that if you are looking for a subset of another group or matching based on id, you will use something like

subset(df1, df1$id %in% idNums1) 

My question is how to do the opposite or select elements that do not match the identifier vector.

I tried to use ! but I get an error

 subset(df1, df1$id !%in% idNums1) 

I think my backup should do something like this:

 matches <- subset(df1, df1$id %in% idNums1) nonMatches <- df1[(-matches[,1]),] 

but I hope that there is something more efficient.

+51
r subset
Mar 24 2018-12-12T00:
source share
1 answer

The expression df1$id %in% idNums1 creates a logical vector. To undo this, you need to nullify the whole vector:

 !(df1$id %in% idNums1) 
+103
Mar 24 2018-12-12T00:
source share



All Articles