title: Use values of one vector as index range for another vector
body: <p>I provide two vectors here:</p>
  <pre><code>vec1 &lt;- c(5, 2, 2, 2, 2, 3, 2, 3, 9, 6, 2, 2, 2, 3)
  
  vec2 &lt;- c(1.96845698, 1.11342534, 0.82580110, 0.35762122, 0.07210485, 0.06046759, 0.93615974, 0.85691566, 0.39439991,
            0.26110080, 1.22082336, 0.71940824, 0.32571803, 0.46358160, 0.16009616, 0.13348428, 1.16801097, 0.30184661, 
            0.51190796, 1.69680701, 0.54418158, 0.74969466, 0.17246107, 0.66953561, 1.02689205, 1.67408220, 1.20311478, 
            0.74049935, 0.55211334, 0.31037724, 0.23620425, 0.34532764, 1.64696898, 0.23094382, 0.67733098, 0.32226374, 
            0.25774802, 0.35768477, 0.27219803, 0.02042260, 0.53784081, 1.27521977, 0.07043151, 0.11879638, 0.13358880)
  </code></pre>
  <p>Now I would like to calculate the mean values of different parts from <code>vec2</code>. The length of these parts is determined by the values of <code>vec1</code>.</p>
  <p>So the output is supposed to be a vector of the same length as <code>vec1</code>.</p>
  <p>The first value of this output vector should be the <code>mean</code> of <code>vec2[1:5]</code>, since <code>vec1[1] = 5</code>. The second value should then be the <code>mean</code> of <code>vec[6:7]</code>, since <code>vec[2] = 2</code> and so forth until the last value of the output vector should correspond to the <code>mean</code> of <code>vec2[43:45]</code>, since the last value of <code>vec1</code> is <code>3</code>.</p>
  <p>I hope it is clear what I mean.</p>
  <p>Here I calculated manually the expected output vector:</p>
  <pre><code>vec3 &lt;- c(0.8674819, 0.4983137, 0.6256578, 0.7409621, 0.5225631, 0.2523873, 0.7349288, 
            0.9176322, 0.7887523, 0.5765066, 0.3077164, 0.1463103, 0.9065303, 0.1076056)
  </code></pre>
  <p>Anybody with an idea, how to do that?</p>