fm <- lm(formula = y ~ x, data = d) # This is the key formula for regression. lm stands for linear model # it has the parameters formula e.g. y~x (reads is in proportion to) # and data containing the data.frame with y,x values # The model yields a result that is stored in fm # from fm we extract the predicted values with predict(fm) d$predicted = predict(fm) # We can also extract the residuals (erros) with residuals(fm) d$residuals = residuals(fm) # knitr::kable plots the values as a table knitr::kable(head(d))