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?
get(value[i]). Or, maybe better,df1[[ value[i] ]].