I need two for loops. Like this:
for (i in seq_along(dat1)[25:30])
for(j in seq_along(dat1)[2:7]) {
print(summary(r <- lm(dat1[,j] ~ dat1[,i]+Jan+Nov, data=dat1)))
}
Now I would like to condition the output, that I only get the diagonals and not all possible permutations, so the first of i and the first of j. How do I do this?
I tried the if statement but if (i==j) doesn’t work and I don’t know how to specify it correctly.
You could try
if ((i-23) == j). But the following command may be easier:This will avoid the permutations you are not interested in.