Re: [R] Summary statistics across factor levels

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Wed, 30 Apr 2008 08:41:19 -0300

Try this:

sek <- seq(1, nrow(Indometh), 9)
Indometh$time[sek] <- NA
Indometh$timeclass <- factor(cut(Indometh$time, breaks=c(0,2,4,6,8,10))) x <- summary(conc ~ Subject + timeclass, method="cross", data=Indometh) vec <- x$S
dim(vec) <- attr(x, "out.attrs")$dim
dimnames(vec) <- attr(x, "out.attrs")$dimnames as.data.frame(vec)

On Wed, Apr 30, 2008 at 7:27 AM, Lauri Nikkinen <lauri.nikkinen_at_iki.fi> 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?
>
> #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"))
>
> #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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


______________________________________________ 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:44:44 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 - 14: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