I came across this code
fm <- y ~ x
mods <- setNames(as.list(1:4), paste0("lm", 1:4))
# loop over the four datasets in the quartet
for(i in 1:4) {
fm[2:3] <- lapply(paste0(c("y","x"), i), as.name)
mods[[i]] <- lmi <- lm(fm, data=anscombe)
I guessed the ~ in this case referring to the linear relationship between y and x, but what is its "overall" meaning?
Also, what exactly is the variable fm and what does the index [2:3] (as in fm[2:3]) refer to? Can someone please explain?