Re: [R] Summary statistics across factor levels

From: Frank E Harrell Jr <f.harrell_at_vanderbilt.edu>
Date: Wed, 30 Apr 2008 05:56:19 -0500

Lauri Nikkinen wrote:
> R users,
>
> I intention is to calculate some summary statistics across factor
> levels. I know that in Hmisc package there is a summary function which
> produces neat summary statistics when using "cross" option. I would
> like to produce similar output with N and Missing columns but produce
> a data.frame. Is there any built-in function for that?

Take a look at the Hmisc summarize function.

>
> #example data
> install.packages("Hmisc")
> library(Hmisc)
> sek <- seq(1, nrow(Indometh), 9)
> Indometh$time[sek] <- NA
> Indometh$timeclass <- factor(cut(Indometh$time, breaks=c(0,2,4,6,8,10)))
> Indometh
> with(Indometh, summary(conc ~ Subject + timeclass, method="cross"))

If using summary I suggest summary(conc ~ Subject + cut2(time, c(0,2,4,6,8,10)), data=Indometh, method='cross')

Frank

>
> #similar with aggregate and reshape but no N or Missing count
> i.mean <- aggregate(Indometh$conc, list(Indometh$Subject,
> Indometh$timeclass), mean, na.rm=T)
> i.mean.rhsp <- reshape(i.mean, v.names="x", idvar="Group.1",
> timevar="Group.2", direction="wide")
> i.mean.rhsp # N and missing columns needed
>
> Thanks,
> Lauri
>
> ______________________________________________
> 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.
>

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
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 Wed 30 Apr 2008 - 12:08:27 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 Wed 30 Apr 2008 - 12:30:33 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