R codes for math project