Perform an ANOVA for each individual level of a factor in R

僤鯓⒐⒋嵵緔 提交于 2019-12-03 09:14:46

Using base lapply:

lapply(split(df, df$Letter), aov, formula=Question ~ Number)

Alternatively using dplyr:

library(dplyr)
obj <- df %>% group_by(Letter) %>% do(model = aov(Question~Number, data = .))
obj$model

Using data.table:

library(data.table)
df <- as.data.table(df)
df[, list(Model = list(aov(Question ~ Number))), keyby = Letter]$Model
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!