R codes of R programming assignment 2