This is a way of using sapply(). I am wondering if there is a way to store the result for each outcome somehow. I saw a solution using lapply() which allows storing the result for each outcome, but I am not sure how to make it work for my situation. Any advice would be appreciated.
varlist <- grep("num_weeks_", names(crao2), value=TRUE)
sapply(varlist, function(my){
f <- as.formula(paste(my, "~ tx", sep=""))
summary(aov(f, data=crao2))
TukeyHSD(aov(f, data=crao2))
})