Alternatively, you can loop over the responses to create a list where each eleemnt corresponds to one model instead of the excellent answer from Roland which generates a 'single' model with multiple responses. This could be usefule if you want (in a later step) work with the generated models seperately:
responseList <- names(iris)[-5]
modelList <- lapply(responseList, function(resp) {
mF <- formula(paste(resp, " ~ Species"))
aov(mF, data = iris)
})
Then you could use lapply
again to run the summary
on the aov
models:
lapply(modelList, summary)
As mentioned, the solution from Roland gives you a multiple responses model (class(fit)
) whereas the solution above gives you a list of (single) response models. Whatever you prefer mainly depends on how you want to work with the result.