[R] tapply

Petr PIKAL petr.pikal at precheza.cz
Tue Apr 10 11:09:14 CEST 2007


Hallo

Seems to me that you can make a summary table using

aggregate(RESPONSE, list(TREATMENT, MEASUREMENT, BLOCK, STUDY), mean)

and then if you want you can use reshape function or melt/cast function 
from reshape package to get wide form of your table.

Regards

Petr Pikal
petr.pikal at precheza.cz

r-help-bounces at stat.math.ethz.ch napsal dne 10.04.2007 00:14:15:

> Hi,
> 
> I have a summary table for an experiment that looks like this
> 
> STUDY BLOCK  TREATMENT MEASURMENT RESPONSE
> A      1       T-0       1         12
> A      1       T-1       1         52
> A      1       T-0       2         12
> A      1       T-1       2         65
> 
> and so on...
> 
> there are 10 studies, 4 blocks, 10 treatemnts, 5 measurments for
> the response value.
> 
> I want to produce a table that looks like this:
> 
> STUDY BLOCK TREATMENT MEAS.1 MEAS.2 MEAS.3
> A       1     T-1      15     54     65
> A       1     T-2      54     65     45
> A       2     T-1      12     12     23
> A       2     T-2      65     54     65
> 
> and so on...
> 
> with tapply(RESPONSE, list(TREATMENT, MEASUREMENT, BLOCK, STUDY), mean)
> 
> I get very close, however, I get the results as a list!
> 
> if instead I use
> 
> ftable(tapply(RESPONSE, list(TREATMENT, MEASUREMENT, BLOCK, STUDY), 
mean))
> 
> I get REALLY close, but the I get only one value for each class, however 
I
> need to whole table, because at the end, what I really need is the
> increment between MEASUREMENT (n) - Measurement (n-1) for each 
TREATMENT,
> BLOCK, STUDY, to perform a ANOVA analysis over increment data.
> 
> Esentialy, I want to move away from running a pivot-table in ACCESS
> 
> Any thoughts?
> 
> Cristian Montes
> North Carolina State University
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list