I would be grateful if you could help me. I've imported a dataframe from Excel (9 columns, whose the first one contains the treatments of an experiment). I'd like to perform an ANOVA analysis (followed by a Tukey post hoc) of each variable (i.e. columns 2 to 9) by the first column of the treatmnents. I think I need a for loop for this instead of typing and carrying out 8 separeted tests (one for each combination "column-i with column-treatment").
I whish someone could give me tips to write the code.
#Invent some data
DF <- data.frame(Treat = rep(LETTERS[1:4], 100, replace = TRUE),
A = rnorm(400),
B = rnorm(400),
C = rnorm(400),
D = rnorm(400),
E = rnorm(400),
F = rnorm(400),
G = rnorm(400),
H = rnorm(400))
#Make a list to store the results
FITS <- vector(mode = "list", length = 8)
for (i in 2:9){
FITS[[i-1]] <- aov(DF[[i]] ~ DF[[1]])
}
FITS[[1]]
#> Call:
#> aov(formula = DF[[i]] ~ DF[[1]])
#>
#> Terms:
#> DF[[1]] Residuals
#> Sum of Squares 2.3112 444.9797
#> Deg. of Freedom 3 396
#>
#> Residual standard error: 1.060041
#> Estimated effects may be unbalanced