Edited R programming assignment 2