您可以尝试这样的操作,但可能需要考虑多个比较:
library(data.table)
DT <- data.table("GROUP" = c("GR1", "GR1", "GR1", "GR2", "GR2")
, "Weight" = c(78, 85, 84.3, 70, 67)
, "BloodPres" = c(11, 14, 13, 12, 12)
, "Heart" = c(140, 130, 142, 135, 120)
, "Glucose" = c(80, 110, 95, 97, 105))
Outcomes <- c("Weight", "BloodPres", "Heart", "Glucose")
sapply(Outcomes, function(my) {
f <- as.formula(paste(my, "~GROUP", sep=""))
summary(aov(f, data=DT))
})
这适用于单向,但是您需要将其调整为两向(请参阅Correct use of sapply with Anova on multiple subsets in R)。