[R] get statistics by group

Mark Myatt mark at myatt.demon.co.uk
Thu Mar 15 13:10:30 CET 2001


Yu-Ling Wu <yuling5 at yahoo.com> writes:
>Hi,
>
>I have a data set look like this:
>
>=================================
>Fruit   Quty
>apple   20
>banana  10
>orange  17
>apple   30
>apple   15
>orange  26
>banana  15
>.........and so on ..........
>=================================
>
>The level of fruit is 30, that is, there are 30 
>different fruits. I'd like to compute some simple 
>statistics for each different fruit and get output 
>like this:
>
>=================================
>        min   max  avg  median
>apple   12     70   25     22
>banana  10     65   19     18
>orange  19     50   27     25
>....... and so on........
>=================================
>
>Please help me with this.
>

Try:

        by(Quty, Fruit, summary)

Mark




--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list