R script modified with the point 1. completed