[R] Filter out some levels?
Chuck Cleland
ccleland at optonline.net
Tue Feb 24 11:12:51 CET 2004
Christian Schulz wrote:
> 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) ,]
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 ?"=="
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list