title: Reshape multidimensional array
body: <p>I have an array representing hourly temperature data, and want to compute daily maxima (or minima, or means).  I can do this using a for loop, but I am sure there must be many better ways to do this in R.  </p>
  
  <pre><code>require(ncdf4)
  nc &lt;- nc_open('file.nc')
  t2 &lt;- ncvar_get(nc,var='T2')  # [ncols, nrows, nsteps]
  </code></pre>
  
  <p>Now t2 is an array with 744 hourly time steps for a 31-day month.  What I want is:</p>
  
  <pre><code>t2.max[ncols, nrows, 31]
  </code></pre>
  
  <p>or, more generally, I would like to reshape t2 to:</p>
  
  <pre><code>t2.reshape[ncols, nrows, ndays, 24]
  </code></pre>
  
  <p>and from there I can use apply to compute daily means or maxima or whatever.</p>
  
  <p>I want the result to be an array, not a data frame.</p>
  
  <p>Suggestions?  I tried using melt/cast from the reshape package, but could not understand how to specify the desired formula.</p>