Sorry,I miss a word:"If I wanna calculate each group's mean extra"


2011/8/16 Lao Meng <laomen...@gmail.com>

> Hi all:
> My data:data(sleep)
>
> If I wanna calculate each group's extra,what I can do is:
> #method1
> attach(sleep)
> mean(extra[group==1])
> mean(extra[group==1])
>
>
> #method2
> result<-matrix(,0,2)
> g<-split(sleep,sleep$group)
> for(i in 1:length(g))
> {
> result<-rbind(result,data.frame(unique(g[[i]]$group),mean(g[[i]]$extra)))
> }
> colnames(result)<-c("name","mean")
>
> But the above 2 method is a little bit tedious.Is there a "short cut"
> manner to get the same result?
>
> Thanks a lot!
>
> My best
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to