Anova, for loop to apply function

后端 未结 1 876
借酒劲吻你
借酒劲吻你 2021-01-19 11:31
>str(set)
\'data.frame\':   1000 obs. of  6 variables:
$ ID       : Factor ..
$ a : Factor ..
$ b: Factor ..
$ c: Factor ..
$ dat    : num  ..
$ contrasts : Ord.f         


        
相关标签:
1条回答
  • 2021-01-19 12:30

    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.

    0 讨论(0)
提交回复
热议问题