title: How do I write codes to calculate the following averages in an array?
body: <p>Apologies if this is too simple. I have been looking but not able to solve it.</p>
  <p>Dimensions of my data looks like this</p>
  <p>y is [1:267, 1:3, 1:10]</p>
  <p>It basically represents 267 sites, 3 surveys every year for 10 years. Whole data is in 0s and 1s</p>
  <p>I want to get two different values.</p>
  <p>Temporal value</p>
  <ol>
  <li>average of each year. Basically, sum of values of 267 sites/ 267*3
  The outcome I am expecting should be 10 values for 10 different years.</li>
  </ol>
  <p>Spatial</p>
  <ol start="2">
  <li>average of all years and surveys at 267 sites.
  The outcome I am expecting should be 267 values for 267 sites.</li>
  </ol>
  <p>This is how I created my array.</p>
  <pre><code>y &lt;- array(NA, dim=c(nsite, nsurvey, nyear))
  date &lt;- array(NA, dim=c(nsite, nsurvey, nyear))
  for (t in 1:nyear) {
    for (j in 1:nsurvey) {
      y[,j,t] &lt;- detect[,3*t-3+j]; date[,j,t] &lt;- dates[,3*t-3+j]
    }
  }
  </code></pre>
  <p>I am trying to write this code in R</p>