added R codes for midterm submission