Skip to content

Filter out some levels?

3 messages · Christian Schulz, Chuck Cleland, Douglas Bates

#
Hi ,

how is it possible t cut some levels from one factor to  subsetting  a 
data.frame on?

subdata <- subset(data, data$FACTOR="1" | 
data$FACTOR="BETA" | data$FACTOR="XY")
???

Maybe a modifcation here is better, but how?
mergex[mergex$PLZX %in% levels(mergex$PLZX) ,]


Many thanks and regards,
Christian
#
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 ?"=="
#
Christian Schulz <ozric at web.de> writes:
Use %in%

subdata <- subset(data, FACTOR %in% c("1", "BETA", "XY"))