Got rid of the `for` loop by using `sapply()` and `seq_along`