Solution for coursera R_programming class