adding R solution to problem 3