Skip to content
Prev 44750 / 398502 Next

Filter out some levels?

Christian Schulz wrote:
Christian:

You need element by element comparison.  Does this help?

mydata <- data.frame(FACTOR = c("1", "BETA", "XY", "DROP"), Y = 
runif(4))

mydata[mydata$FACTOR=="1" | mydata$FACTOR=="XY" | 
mydata$FACTOR=="BETA",]

   FACTOR         Y
1      1 0.5111390
2   BETA 0.7219460
3     XY 0.1346707

mydata[mydata$FACTOR!="DROP",]

   FACTOR         Y
1      1 0.5111390
2   BETA 0.7219460
3     XY 0.1346707

See ?"=="