lapply
is faster than for loop and does the same trick:
First define a vector with names of your wavelengths. Doing this precisely is difficult, because you did not include example data.
wavs <- c("X350", "X...", "X...",...)
As you have so many wavelengths you probably do not want to do this manually. Include an example of your data, so it's easier to advice, but say you had them as columns of a data frame (guessing from X350):
require(reshape2)
wavdata <- melt(mydata, id = "structure")
wavs <- levels(wavdata$variable)
Then you can go ahead and do the loop:
mods <- lapply(wavs, function(i) {
x <- subset(wavdata, variable == wavs)
mod_structure1 <- lm(variable ~ value, data=x)
anova(mod_structure1)})
This gives you an incredible list of ANOVAs, so be prepared. It might be better to get relevant parameters from those ANOVAs to a data.frame, which is then easier to handle.
mod.data <- lapply(wavs, function(i) {
x <- subset(wavdata, variable == wavs)
mod_structure1 <- lm(variable ~ value, data=x)
tmp <- anova(mod_structure1)
data.frame(Df = tmp$Df[[1]], F = tmp$F[[1]], p = tmp$P[[1]])
})
do.call(rbind, mod.data)
The code is not tested and might contain errors. However, you can generate your own from the idea behind it.