R codes written by Kuber