Implementation for R Programming - assignment 2