R solution for project 2