R is equipped with the command lm to fit the linear models:
Input:
source_code/appendix_b_r/example07_linear_regression.r temperatures = data.frame( fahrenheit = c(5,14,23,32,41,50), celsius = c(-15,-10,-5,0,5,10) ) model = lm(celsius ~ fahrenheit, data = temperatures) print(model)
Output:
$ Rscript example07_linear_regression.r Call: lm(formula = celsius ~ fahrenheit, data = temperatures) Coefficients: (Intercept) fahrenheit -17.7778 0.5556