[R] strange split behavior?

Philipp Pagel p.pagel at wzw.tum.de
Wed Sep 23 14:49:38 CEST 2009


On Wed, Sep 23, 2009 at 07:29:30AM -0500, Peng Yu wrote:
> On Wed, Sep 23, 2009 at 1:24 AM, Peter Dalgaard
> <p.dalgaard at biostat.ku.dk> wrote:
> > Peng Yu wrote:
> 
> Is there an operation on a factor to get a subset and keep only the
> corresponding levels (see commented line below)?

Yes, there is: call factor() on your subset:

> a <- factor(rep(letters[1:5], 5))
> a
 [1] a b c d e a b c d e a b c d e a b c d e a b c d e
Levels: a b c d e
> b <- a[a!='b']
> b
 [1] a c d e a c d e a c d e a c d e a c d e
Levels: a b c d e
> factor(b)
 [1] a c d e a c d e a c d e a c d e a c d e
Levels: a c d e


cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/




More information about the R-help mailing list