[R] %in% operator - NOT IN

Duncan Mackay mackay at northnet.com.au
Sun May 8 14:52:24 CEST 2011


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 !"
>
>
>Thanks!
>
>Dan
>
>XXXX
>
>         [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>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
ARMIDALE NSW 2351
Email: home mackay at northnet.com.au



More information about the R-help mailing list