R programming assignment, attempt 1