[R] strange split behavior?
Petr PIKAL
petr.pikal at precheza.cz
Wed Sep 23 16:44:58 CEST 2009
Hi
r-help-bounces at r-project.org napsal dne 23.09.2009 14:49:38:
> 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']
Or use drop argument
b <- a[a!='b', drop=TRUE]
regards
Petr
> > 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/
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list