[R] Collapsing across trials

Pedro Alcocer pealco at gmail.com
Sun Dec 17 07:54:29 CET 2006


Thanks so much, Hadley. That's exactly what I needed.

My only comment is that the line

cast(Subj + List + Condition ~ variable , mean)

should be

cast(dfm, Subj + List + Condition ~ variable , mean)

Your excellent demo on your site cleared that up quickly, however.

Thanks again,

Pedro




On 12/17/06, hadley wickham <h.wickham at gmail.com> wrote:
> On 12/16/06, Pedro Alcocer <pealco at gmail.com> wrote:
> > Hello,
> >
> > My ultimate goal is a repeated measures (mixed model) ANOVA, however,
> > my present question is about how to reorganize my data into the format
> > that the ANOVA commands expect. In particular, how to collapse across
> > trials. (I am using the tutorial at
> > [http://personality-project.org/r/r.anova.html] for the mixed model
> > ANOVA)
> >
> > The data I am using looks like this. A subject sees 10 trials per
> > condition and there are 2 conditions. I want the average of all the
> > reaction times (RTs) from a subject looking a one condition. I also
> > want to retain List in the final output.
>
> Have a look at the reshape package, http://had.co.nz/reshape.
>
> The following code should do what you want:
>
> install.packages("reshape")
> library(reshape)
> dfm <- melt(df, id=c("Subj", "List","Condition"))
> cast(Subj + List + Condition ~ variable , mean)
>
> (that should work with any number of rt variables)
>
> Hadley
>



More information about the R-help mailing list