Re: [R] factors ordered by mean

From: hadley wickham <h.wickham_at_gmail.com>
Date: Wed, 20 Feb 2008 21:24:16 -0500

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/

______________________________________________
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.
Received on Thu 21 Feb 2008 - 02:27:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Feb 2008 - 03:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive