R code for SOA Exam P