Solving financial problems in R