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)+1000Error: unexpected '!' in "data2[data1$char1 !" Thanks! Dan XXXX [[alternative HTML version deleted]]
G'day Dan, On Sun, 8 May 2011 05:06:27 -0400 Dan Abner <dan.abner99 at gmail.com> 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 !"Try (untested) R> data2[!(data1$char1 %in% c("string1","string2")),1]<-max(data1$x1)+1000 HTH. Cheers, Berwin
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 >stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide 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