Revised R scripts with more efficient, cleaner code. (Push after grading was closed. Just updating for later reference.)