Cached matrix implementation, ex2 in R programming