[R] Summary statistics across factor levels

Lauri Nikkinen lauri.nikkinen at iki.fi
Wed Apr 30 12:27:09 CEST 2008

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?

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

#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


More information about the R-help mailing list