0

I'd like to split the content of my data frame into two based on whether or not the data contain "ID" column values specified in a second list.

I have dplyr loaded and %in% below works well, but get but %!in% returned the following error:

D2a<-D1[D1$ID%in%modtab2$ID,]

> D2b<-D1[D1$ID%!in%modtab2$ID,]
> Error in lapply(x, `[`, i) : could not find function "%!in%"

Suggestions on a fix?

Julien Navarre
  • 7,653
  • 3
  • 42
  • 69
Jina
  • 1
  • 1

1 Answers1

1

As the error message said %!in% isn't a R function.

You have to negate the whole expression e.g. !(x %in% y)

So you can probably do : D1[!(D1$ID %in% modtab2$ID), ]

You can also create a custom %!in% function :

`%!in%` <- function(x, y) !(x %in% y)
Julien Navarre
  • 7,653
  • 3
  • 42
  • 69