doing problem 3.14 in R