title: R - Array data loop selection
body: <p>i want to select June, July and August data from the 3D array (<code>ssta_sst</code>, 360*180*362).</p>
  
  <p>the loop works but the output of ssta_winter has the identical values for <code>ssta_winter[,,i]</code>.seen below. I have set it up as an array of (360,180,29).</p>
  
  <p>I think the problem is the variable <code>temp</code>, i want to define it as an array first but i don't know what size it should be (360,180,3) or (360,180,3*29) and how to keep a loop counter in <code>temp</code> when it passes down to finding mean stage?</p>
  
  <pre><code>ssta_winter = array( data=NA, dim = c(360,180,29))
  temp = array( data=NA, dim = c(360,180,3))
  
  for (yr in 1982:2010) {
      temp &lt;- ssta_sst[,,year_sst==yr &amp; (month_sst&gt;=6 &amp; month_sst&lt;=8)]
      for (i in 1:360) {
          for (j in 1:180) {
              ssta_winter[i,j,] &lt;- mean(temp[i,j,])
          }
      }
  }
  
  &gt; for (i in 1:29){
  + print(ssta_winter[180,166,i])
  + }
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  [1] 0.2222583
  </code></pre>