I want to calculate 2-way anova to my df
df
O H Variable Value
NN HI+ AM 0.03493450
NN HI+ AM 0.00000000
NN HI+ AM 0.09170306
NN HI- AM 0.05240175
NN HI- AM 0.05676856
NN HI- AM 0.06986900
HP HI+ AM 0.30131004
HP HI+ AM 0.43231441
HP HI+ AM 0.34497817
NN HI+ AD 0.03493450
NN HI+ AD 0.00000000
NN HI+ AD 0.09170306
NN HI- AD 0.05240175
NN HI- AD 0.05676856
NN HI- AD 0.06986900
HP HI+ AD 0.30131004
HP HI+ AD 0.43231441
HP HI+ AD 0.34497817
Fo a single variable I use
aov2<-aov(Variable~O+H+O:H, data=df)
I am wondering if I can avoid a loop and apply(ddply)?
The aov
function is not designed to do this by default. You will have to code the choosing of the variables by hand. What you can do is subset the data.frame so that it will contain only your variables and you can use a generic formula
aov(y ~ ., data = df.subsetted)