Reputation: 1178
I want to run an ANOVA test on several data (Day, Week and Month). My idea was to create a loop that call each dataset (Day, Week and Month). However the following code does not work, because does not recognise the value[i].
df1<-data.frame(Day=c(1,2,5,6,9,8),Week=c(22,45,33,3,2,11),Month=c(45,6,7,12,4,7),
type=c("A","C","B","A","C","B"))
value<-c("Day","Week","Month")
for(i in 1:length(value)){
av<-aov(value[i] ~ type, data = data)
return(av)
}
Do you have any suggestion on how I could improve the code?
Upvotes: 0
Views: 50
Reputation: 132651
You don't need a loop:
m <- aov(cbind(Day, Week, Month) ~ type, data = df1)
summary(m)
Upvotes: 2