implement functions of R programming assignment2