[R] Simple summary question

Thomas Lumley tlumley at u.washington.edu
Thu Jan 10 17:49:31 CET 2002


On 9 Jan 2002, A.J. Rossini wrote:

> >>>>> "AP" == Andrew Perrin <andrew_perrin at unc.edu> writes:
>
>     AP> I'd like to get summary statistics (really just a mean would
>     AP> be fine) for a vector in a data frame, but split based on the
>     AP> value of another vector.  That is, I have a data frame
>     AP> (hcd.df) with variables datecat (which is always 1 or 2) and
>     AP> auth.sum (-8..+8).  I've used xtabs to get chi-square
>     AP> comparisons, but what I need now is a simple mean of auth.sum
>     AP> where datecat is 1 and another where datecat is 2. Thanks for
>     AP> any advice.
>
> Something like :
>
>         lapply(split(hcd.df$auth.sum,hcd.df$datecat),mean)
>

Or
    tapply(hcf.df$auth.sum, hcd.df$datecat, mean)

or (in 1.4.0)

    with(hcf.df, {tapply(auth.sum, datecat, mean})


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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