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.
require(ncdf4)
nc <- nc_open('file.nc')
t2 <- ncvar_get(nc,var='T2') # [ncols, nrows, nsteps]
Now t2 is an array with 744 hourly time steps for a 31-day month. What I want is:
t2.max[ncols, nrows, 31]
or, more generally, I would like to reshape t2 to:
t2.reshape[ncols, nrows, ndays, 24]
and from there I can use apply to compute daily means or maxima or whatever.
I want the result to be an array, not a data frame.
Suggestions? I tried using melt/cast from the reshape package, but could not understand how to specify the desired formula.