title: How to apply a function to a three dimensional array in R
body: <p>I have a three dimensional array containing time (in years), latitude, and longitude. I would like to count the number of zeros a given coordinate has over the entire timescale by using the apply function. I have written a function to count the number of zeros when I specify a latitude and longitude, but I cannot seem to apply this function over the entire array. My code:</p>
  <pre><code>#to sum zeros at a given lat and lon across all years combined
  sum.zero &lt;- function(x, lat, lon) {
    sum(is.zero(x[,lat,lon]))
    
  }
  
  #to test for zero 
  is.zero &lt;- function(x) {
    x == 0 
  
  
  }
  </code></pre>
  <pre><code> numberofzeros &lt;- apply(data, c(2,3), sum.zero)
  
   Error in x[, lat, lon] : incorrect number of dimensions 
  </code></pre>