title: R: Calculate the mean and variance of length N elements in a vector
body: <p>I'm new to R.</p>
  <p>I'm trying to calculate the mean and variance of a vector.</p>
  <p>However rather than simply calculating the mean and variance of the <em>whole</em> vector, I am trying to calculate the mean and variance of each &quot;block of 10 elements&quot;.</p>
  <p>For example</p>
  <pre><code>v &lt;- c(1:100)
  mean(v) # returns 50.5
  var(v) # returns 841.6667
  </code></pre>
  <p>what I actually want is a new vector, with length 10, containing this:</p>
  <pre><code>mean(v[1:10]), mean(v[11:20]), ... , mean(v[91:100])
  </code></pre>
  <p>(and also the variance)</p>
  <pre><code>var(v[1:10]), var(v[11:20]), ... , var(v[91:100])
  </code></pre>
  <p>However I don't know how to accomplish this in a sensible way. Any help appreciated even if that is &quot;go read this reference at [url]&quot;. I tried duckduckgo searching for this, but to no avail.</p>
  <p>Seems like something that should be easy?</p>