R Programming Caching the Mean of a Vector