Anova, for loop to apply function

大城市里の小女人 提交于 2019-12-01 20:14:07

This ought to do it:

# Sample data
set <- data.frame(ID=1:10, a=letters[1:10], b=LETTERS[1:10], c=letters[10:1],
                  dat=runif(10), contrasts=ordered(rep(1:2, 5)))
X <- letters[1:3] # a,b,c

sapply(X, function(my) {
  f <- as.formula(paste("dat~contrasts*",my,"+Error(ID/(contrasts))"))
  summary(aov(f, data=set))
}, simplify=FALSE)

Note the use of sapply with simplify=FALSE. Using lapply also works, but it doesn't add names to the list components.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!