Value Iteration in R