Adding column to table in a for loop
If you look at the doc for cbind, which you already use, you will see that it can take whole matrices, data.frames, and vectors as inputs. This means you can just do:

TableWithResiduals &lt;- cbind(iris, Residual_value = resid(lmfit))


You could also have done:

TableWithResiduals &lt;- iris
TableWithResiduals$Residual_value &lt;- resid(lmfit)


If it were not for these solutions, there are a few things that could be improved in your code. First, you could have used row directly instead of the out_index variable you created. Second, the last two lines of your code could have been merged into one: names(TableWithResiduals) &lt;- c(names(iris), "Residual_value"). Also, if you look at the doc for lm, you could have saved yourself some typing by doing lm(Petal.Width ~ Sepal.Length + Sepal.Width, iris)