There are couple of ways where you can perform the same task. Sometimes in this book, I may do it more efficiently and sometimes not. There are mainly two reasons that will prevent me from trying a more efficient way:
- I want to display a more step-wise approach so that newcomers won't feel discouraged
- I am not that smart
There is always room for improvement. I encourage the reader to look for it every single time. It's okay if you don't succeed or if you find people with more skills than you. Next, you can see the code that I would have pulled if it weren't for reason#1:
# set.seed(5)# n <- sample(dim(dt)[1], size = 40)reg <- lm(infantMortality ~ log(ppgdp), data = dt[-n,])out <- predict(reg, newdata = dt[n,])
Instead of creating ...