title: Algorithm for extracting seasonal rainfall totals into a new vector
body: <p>I have four vectors for each season containing the rainfall sum for each season in the period 1926 to 1999. I am trying to create a new vector <code>yearly.totals</code> which will extract elements from the seasonal vectors in such a way that it will contain the rainfall sums for each season ordered by year. It should read:</p>
  
  <pre><code>yearly.totals[1] = spring.totals[1]
  yearly.totals[2] = summer.totals[1]
  yearly.totals[3] = fall.totals[1]
  yearly.totals[4] = winter.totals[1]
  yearly.totals[5] = spring.totals[2]
  yearly.totals[6] = summer.totals[2]
  ...
  </code></pre>
  
  <p>Note my 'year' begins in Spring. So far I have tried the following code:</p>
  
  <pre><code>year.length = length(spring.totals)+length(summer.totals)+length(fall.totals)+length(winter.totals)
  
  yearly.totals = vector("numeric", year.length)
  
  for(i in 1:length(yearly.totals)){
    if(i %in% seq(1,75,4)) {
      yearly.totals[i] = spring.totals[i]
    } else if(i %in% seq(2,75,4)) {
      yearly.totals[i] = summer.totals[i]
    } else if(i %in% seq(3,75,4)) {
      yearly.totals[i] = fall.totals[i]
    } else {
      yearly.totals[i] = winter.totals[i]
    }
  }
  </code></pre>
  
  <p>This identifies which season each element belongs to using <code>seq()</code>. The problem lies in which element it extracts from the seasonal vectors. The first four elements are correct but after that it goes wrong. This is what happens:</p>
  
  <pre><code>yearly.totals[5] = spring.totals[5]
  yearly.totals[6] = summer.totals[6]
  ...
  </code></pre>
  
  <p>I believe the solution might lie in changing the seasonal <code>i</code>th component within the for loop to something other than just <code>i</code>, but I can't figure it out. I tried <code>i - (i-1)</code>, which is fine for the first four elements but then just repeats.</p>
  
  <pre><code>for(i in 1:length(yearly.totals)){
    if(i %in% seq(1,75,4)) {
      yearly.totals[i] = spring.totals[i - (i-1)]
    } else if(i %in% seq(2,75,4)) {
      yearly.totals[i] = summer.totals[i - (i-1)]
    } else if(i %in% seq(3,75,4)) {
      yearly.totals[i] = fall.totals[i - (i-1)]
    } else {
      yearly.totals[i] = winter.totals[i - (i-1)]
    }
  }
  
  yearly.totals[5] = spring.totals[1]
  yearly.totals[6] = summer.totals[1]
  ...
  </code></pre>
  
  <p>Anyone have any ideas?</p>
  
  <p>Many thanks</p>