[R] factors ordered by mean

hadley wickham h.wickham at gmail.com
Thu Feb 21 03:24:16 CET 2008


On Wed, Feb 20, 2008 at 6:02 PM, Ronaldo Reis Junior <chrysopa at gmail.com> wrote:
> Hi,
>
>  How to order the levels os factor not by alphabetic order but by mean of Y.
>  Somethink like this:
>
>  I have this alphabetic order:
>
>  > levels(pH)
>  [1] "alto"  "baixo" "medio"
>
>  the order by mean os yvar is:
>  > sort(tapply(Riqueza,pH,mean))
>    baixo    medio     alto
>  11.56667 20.00000 26.80000
>
>  How to make the levels of pH ordered by this mean to the result to see
>  somethink like this:
>
>  > levels(pH)
>  [1] "baixo"  "medio"  "alto"

Have a look at ?reorder

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list