[R] tapply changing order of factor levels?
alain.guillet at uclouvain.be
Wed May 6 16:05:12 CEST 2009
I don't believe the problem is related to tapply. I would say it is
because of the factor. In fact, the order of a factor is given by the
alphanumerical order of his levels. You can see it with levels(myfactor).
I you want to change the order, redefine the levels of myfactor with the
expected order or use the function ordered.
Chirantan Kundu wrote:
> Does tapply change the order when applied on a factor? Below is the code I
>  IN0020020155 IN0019800021 IN0020020064 IN0020020155 IN0019800021
> IN0019800021 IN0020020064 IN0020020064 IN0019800021
> Levels: IN0020020155 IN0019800021 IN0020020064
> IN0020020155 IN0019800021 IN0020020064
> 2 4 3
> # Everything fine upto this point. The order of levels is maintained as it
> IN0019800021 IN0020020064 IN0020020155
> 4 3 2
> # Now the order has changed.
> Is this the expected behavior? Any idea on how to avoid the change in order?
> Visit us at http://www.2pirad.com
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Statistician and Computer Scientist
SMCS - Institut de statistique - Université catholique de Louvain
Voie du Roman Pays, 20
tel: +32 10 47 30 50
More information about the R-help