1

I try to show the statistic summary of my data in table. my data looks like below:

Sex     Cost    Variance    Numsample
 M       HC       HV         7 
 M       LC       LV         9
 ....
 F       HC       HV         4
 F       LC       LV         3
 ...

As shown above, variable "Sex", "Cost" and "Variance" are all binary, specifically, Sex (M,F); Cost(HC,LC) and Variance (HV,LV). What I want to do here is to show the statistic summary (5 number summary) of Numsample for each group (e.g., 2 Cost X 2 Variance) by different Sex.

I only know how to show results by one group(variable) using tapply() or by() functions. and some others have similar question like this. But I think the result table for my quesion would be something looks like:

Sex:M   
      Cost - HC; Variance - HV
        Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      Cost - LC; Variance - HV
        Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      Cost - LC; Variance - LV
        Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      Cost - HC; Variance - LV
        Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
Sex:F 
      ....(same as above)

Any ideas?

ekad
  • 14,436
  • 26
  • 44
  • 46
Chuan
  • 667
  • 8
  • 22

1 Answers1

1

An idea:

library(plyr)
ddply(my_data, .(Sex,Cost,Variance), function(x) summary(x$Numsample))
gd047
  • 29,749
  • 18
  • 107
  • 146
  • Thanks,George. The ddply() function definitely works for my data. Only thing is the last summary(x$Numsample) part doesn't work as expected and the result table is not very clear to read. Anyway, it is an good idea solve my question! – Chuan Oct 23 '14 at 19:54