Re: [R] %in% operator - NOT IN

From: Duncan Mackay <>
Date: Sun, 08 May 2011 22:52:24 +1000

At 19:06 08/05/2011, you wrote:
>Hello everyone,
>I am attempting to use the %in% operator with the ! to produce a NOT IN type
>of operation. Why does this not work? Suggestions?

> > data2[data1$char1 %in% c("string1","string2"),1]<-min(data1$x1)
> > data2[data1$char1 ! %in% c("string1","string2"),1]<-max(data1$x1)+1000
>Error: unexpected '!' in "data2[data1$char1 !"
> [[alternative HTML version deleted]]
> mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

Hi Dan

See the last of the examples for ?match

"%w/o%" <- function(x, y) x[!x %in% y] #-- x without y (1:10) %w/o% c(3,7,12)

I think it was Peter Dalgaard who pointed this out some years ago

HTH Regards

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Email: home mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sun 08 May 2011 - 12:58:45 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 08 May 2011 - 14:20:06 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive