[R] means and variances of several groups in the matrix
Jim Lemon
jim at bitwrit.com.au
Mon Apr 21 12:31:41 CEST 2008
kathie wrote:
> Dear R users,
>
> I have 32 observations in data x. After sorting this, I want to compute
> means and variances of 3 groups divided by "nr".
>
> Actually, the number of groups is flexible. Any suggestion will be greatly
> appreciated.
>
Hi Kathryn,
One way (there are many others) is to use the brkdn function in the
prettyR package. You have to create a grouping variable, but it's pretty
easy...
group1<-rep(1:3,each=nr[1,])
group2<-rep(1:3,each=nr[2,])
y.df<-data.frame(y=y,group1=group1,group2=group2)
brkdn(y~group1,y.df,num.desc=c("mean","var"))
brkdn(y~group2,y.df,num.desc=c("mean","var"))
Jim
More information about the R-help
mailing list