Reputation: 1716
I have had some trouble tidying avolist
objects. When performing a repeated measures analysis of variance the optput object is usually a list of aov
objects for the different error strata.
datafilename <- "http://personality-project.org/r/datasets/R.appendix5.data"
aov_example <- read.table(datafilename, header = T)
aov_example <- aov(Recall ~ (Task*Valence*Gender*Dosage) + Error(Subject/(Task*Valence)) +(Gender*Dosage), aov_example)
class(aov_example)
[1] "aovlist" "listof"
(example stolen from http://personality-project.org/r/#anova)
To-date, it is not possible to tidy these objects directly because broom::fix_data_frame()
doesn't take lists.
library("broom")
tidy(aov_example)
Error in as.data.frame.default(x) : cannot coerce class "c("aovlist", "listof")" to a data.frame
So I tried to use lapply()
, but this throws an error:
lapply(aov_example, tidy)
Error in `colnames<-`(`*tmp*`, value = c("df", "sumsq", "meansq", "statistic", : Attribute 'names' [5] must be of same length as vector [3]
Is there an easy fix for this?
Upvotes: 3
Views: 1486
Reputation: 78620
A tidy.aovlist
method has been added to broom as of version 0.3.6, so that one can simply do:
tidy(aov_example)
without needing lapply
.
Upvotes: 5
Reputation: 21425
You can try this:
lapply(summary(aov_example),function(x){tidy(x[[1]])})
It will give you a list of datatables with the degrees of freedom, sum of squares..
Upvotes: 2