Reputation: 161
I want to do an ANOVA test with my abundance data of different stations, I want to know what is the correct way to write the script because all examples with aov function are related to a formula but I do not be sure that this formula takes account all columns comparing their means.
The following data are a single example of the way that I use to try to do the test. But there are is not a categorical variable in the columns, for this reason, I am sure that this way is wrong.
Thanks for your help
set.seed(200)
D <- data.frame(a=sample(15),b=sample(15), c=sample(15))
A<-aov(a~c, data = D)
Upvotes: 1
Views: 1810
Reputation: 76450
You need first to reshape the data.frame
from wide to long format.
The following uses an external package, reshape2
, to reshape the data from wide to long format.
molten <- reshape2::melt(D)
head(molten)
model <- lm(value ~ variable, data = molten)
anova(model)
Upvotes: 1