[R-sig-ME] Summary of Subgroups

Ben Bolker bbolker at gmail.com
Fri Aug 8 01:40:33 CEST 2014


On 14-08-07 07:17 PM, Shankar Lanke wrote:
> Dear R group,
> 
> I have a query about summarizing the sub groups. I want to calculate mean
> or median of  BMI & SWTZ of ID 1 to 3 as shown in below table. Actually I
> have 4500 ID's.
> I appreciate your assistance and guidance.
> 
>   ID BMI SWTZ  1 22.3 97.7  1 22.3 116  1 22.3 116  1 22.3 110.8  1 22.3
> 110.8  2 27.3 135.8  2 23 119  2 29.4 65.4  2 29.4 65.4  2 29.4 65.4  3 22.3
> 128.1  3 22.3 128.1  3 22.3 128.1  3 22.3 128.1  3 22.3 114.7
> 
> Thank you very much in advance.
> 

  This seems to be a basic R question, not particularly mixed-model related?

  I would try

library("plyr")
ddply(your_data,"ID",summarise,meanBMI=mean(BMI),medBMI=median(BMI),
        meanSWTZ=mean(SWTZ),medSWTZ=median(SWTZ))

There are many other ways to do this, some faster.
Follow-ups to r-help or stackoverflow please.

  Ben Bolker



More information about the R-sig-mixed-models mailing list