corrected r code