[R] extracting the levels of a subset of data

Philipp Pagel p.pagel at gsf.de
Fri Sep 19 12:21:09 CEST 2003


> > tmpdata<-subset(myd, TYPE=="A")
> > levels(tmpdata$TYPE)
> > [1] "A" "B" "C"
> I'd like to get only "A" as output...

rebuild the factor after subsetting:

tmpdata$TYPE <- factor(tmp$TYPE)

If you want the levels of all factors in your data frame to be
adjusted you could also use:

tmpdata <- data.frame(as.matrix( subset(myd, TYPE=='A') ))


Dr. Philipp Pagel                                Tel.  +49-89-3187-3675
Institute for Bioinformatics / MIPS              Fax.  +49-89-3187-3585
GSF - National Research Center for Environment and Health
Ingolstaedter Landstrasse 1
85764 Neuherberg, Germany

More information about the R-help mailing list