title: Caching the mean of a Vector in R
body: <p>I am learning R and came across some code as part of the practice assignment. </p>
  
  <pre><code> makeVector &lt;- function(x = numeric()) {
           m &lt;- NULL
           set &lt;- function(y) {
                  x &lt;&lt;- y
                  m &lt;&lt;- NULL
          }
          get &lt;- function() x
          setmean &lt;- function(mean) m &lt;&lt;- mean
          getmean &lt;- function() m
          list(set = set, get = get,
               setmean = setmean,
               getmean = getmean)
   }
  </code></pre>
  
  <p>The documentation says:</p>
  
  <p>The function, <code>makeVector</code> creates a special "vector", which is
  really a list containing a function to</p>
  
  <ol>
  <li>set the value of the vector</li>
  <li>get the value of the vector</li>
  <li>set the value of the mean</li>
  <li>get the value of the mean</li>
  </ol>
  
  <p>But i can not understand how the function works except for the point that it is assigning mean value to the variable <strong>m</strong> in that particular environment.</p>